Exemplo n.º 1
0
        static void OnIsDeleteButtonEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs?e = null)
        {
            // TODO: cache the buttonStates and buttonVisibleState values on the textBox

            var element = d as FrameworkElement;

            VisualStateGroup?buttonStates       = null;
            VisualState?     buttonVisibleState = null;
            var deleteButton = element?.GetDescendantByName <Button>(DeleteButtonElementName);

            if (deleteButton?.Parent is Grid rootGrid)
            {
                (buttonStates, buttonVisibleState) = InterceptDeleteButtonVisualStates(rootGrid);
            }

            var states = buttonStates?.States;

            if (element is not null && states is not null && buttonVisibleState is not null)
            {
                var isEnabled = GetIsDeleteButtonEnabled(element);
                var contains  = states.Contains(buttonVisibleState);
                if (isEnabled && !contains)
                {
                    states.Add(buttonVisibleState);
                }
                else if (!isEnabled && contains)
                {
                    states.Remove(buttonVisibleState);
                }
            }
        }
            /// <summary>
            ///     Update the IsEnabled value of the UIElement
            /// </summary>
            /// <param name="uiElement">UIElement</param>
            /// <param name="dependencyPropertyChangedEventArgs">DependencyPropertyChangedEventArgs</param>
            protected override void Update(UIElement uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
            {
                var permissions          = GetPermissions(uiElement);
                var permissionsOperation = GetPermissionsOperations(uiElement);

                uiElement.IsEnabled = HasPermissions(permissions, permissionsOperation)
                    ? GetWhenPermissions(uiElement)
                    : GetWhenPermissionsMissing(uiElement);
            }
Exemplo n.º 3
0
        /// <inheritdoc />
        public void Update(DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
        {
            var host = GetHost();

            if (host != null)
            {
                Update(host, dependencyPropertyChangedEventArgs);
            }
        }
Exemplo n.º 4
0
        static void OnIsReadOnlyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs?e = null)
        {
            var element = d as FrameworkElement;
            var textBox = element?.GetDescendantByName <TextBox>("TextBox");

            if (textBox != null)
            {
                textBox.IsReadOnly = true;
            }
        }
Exemplo n.º 5
0
        static void OnVerticalTextAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs?e = null)
        {
            // TODO: cache the scrollViewer value on the textBox

            var element      = d as FrameworkElement;
            var scrollViewer = element?.GetDescendantByName <ScrollViewer>(ContentElementName);

            if (scrollViewer is not null)
            {
                scrollViewer.VerticalAlignment = GetVerticalTextAlignment(d);
            }
        }
Exemplo n.º 6
0
        private void OnPropertyChanged(ManagedWeakReference?instance, DependencyProperty property, DependencyPropertyChangedEventArgs?args)
        {
            if (_svgElement == null)
            {
                return;
            }

            if (property == CenterProperty)
            {
                var center = Center;

                _svgElement.SetAttribute(
                    ("cx", center.X.ToStringInvariant()),
                    ("cy", center.Y.ToStringInvariant()));
                _svgElement.InvalidateMeasure();
            }
            else if (property == RadiusXProperty)
            {
                _svgElement.SetAttribute("rx", RadiusX.ToStringInvariant());
                _svgElement.InvalidateMeasure();
            }
            else if (property == RadiusYProperty)
            {
                _svgElement.SetAttribute("ry", RadiusY.ToStringInvariant());
                _svgElement.InvalidateMeasure();
            }
        }
Exemplo n.º 7
0
 protected override void Update(UIElement uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
 {
     uiElement.Visibility = GetValue(uiElement) ? GetWhenTrue(uiElement) : GetWhenFalse(uiElement);
 }
            protected override void Update(UIElement uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
            {
                _enumCheck.Update(GetValue(uiElement), GetTargetValue(uiElement));

                uiElement.Visibility = _enumCheck.IsMatch ? GetWhenMatched(uiElement) : GetWhenNotMatched(uiElement);
            }
Exemplo n.º 9
0
 protected override void Update(UIElement uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
 {
     uiElement.Visibility = GetValue(uiElement) == null
         ? GetWhenNull(uiElement)
         : GetWhenNotNull(uiElement);
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Let the behavior update it's "stuffT for the specified host
 /// </summary>
 /// <param name="uiElement">THost which extends DependencyObject</param>
 /// <param name="dependencyPropertyChangedEventArgs">DependencyPropertyChangedEventArgs</param>
 protected abstract void Update(THost uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs);
Exemplo n.º 11
0
        private void OnPropertyChanged(ManagedWeakReference?instance, DependencyProperty property, DependencyPropertyChangedEventArgs?args)
        {
            if (_svgElement == null)
            {
                return;
            }

            if (property == StartPointProperty)
            {
                var point = StartPoint;
                _svgElement.SetAttribute(
                    ("x1", point.X.ToStringInvariant()),
                    ("y1", point.Y.ToStringInvariant()));
            }
            else if (property == EndPointProperty)
            {
                var point = EndPoint;
                _svgElement.SetAttribute(
                    ("x2", point.X.ToStringInvariant()),
                    ("y2", point.Y.ToStringInvariant()));
            }
        }
Exemplo n.º 12
0
        private void OnPropertyChanged(ManagedWeakReference?instance, DependencyProperty property, DependencyPropertyChangedEventArgs?args)
        {
            if (_svgElement == null)
            {
                return;
            }

            if (property == FillRuleProperty)
            {
                var rule = FillRule switch
                {
                    FillRule.EvenOdd => "evenodd",
                    FillRule.Nonzero => "nonzero",
                    _ => "evenodd"
                };
                _svgElement.SetAttribute("fill-rule", rule);
            }
            else if (property == ChildrenProperty)
            {
                _svgElement.ClearChildren();

                if (args?.OldValue is GeometryCollection oldGeometries)
                {
                    oldGeometries.VectorChanged -= OnGeometriesChanged;
                }

                if ((args?.NewValue ?? Children) is GeometryCollection newGeometries)
                {
                    newGeometries.VectorChanged += OnGeometriesChanged;

                    newGeometries.SetParent(this);

                    foreach (var child in newGeometries)
                    {
                        _svgElement.AddChild(child.GetSvgElement());
                    }
                }
            }
        }
            protected override void Update(FrameworkElement uiElement, DependencyPropertyChangedEventArgs?dependencyPropertyChangedEventArgs)
            {
                if (uiElement == null)
                {
                    return;
                }

                // For user controls, find the parent - parent
                while (typeof(UserControl).IsAssignableFrom(uiElement.GetType().BaseType))
                {
                    if (!(uiElement.Parent is FrameworkElement parentUiElement))
                    {
                        break;
                    }
                    uiElement = parentUiElement;
                }

                if (!uiElement.IsLoaded)
                {
                    // If the host is not loaded, wait until it is.
                    var target   = uiElement.IsLoaded ? _icon : uiElement;
                    var handlers = new RoutedEventHandler[1];
                    handlers[0] = (sender, args) =>
                    {
                        Update(uiElement, dependencyPropertyChangedEventArgs);
                        target.Loaded -= handlers[0];
                    };
                    target.Loaded += handlers[0];
                    return;
                }

                var iconProperty = GetTargetValue(uiElement);
                var propertyInfo = uiElement.GetType().GetProperty(iconProperty);

                if (propertyInfo == null)
                {
                    return;
                }
                if (propertyInfo.PropertyType == typeof(ImageSource))
                {
                    // Icon is of type ImageSource
                    var image = propertyInfo.GetValue(uiElement) as ImageSource;
                    // Default size for the icon
                    var size = new Size(256, 256);
                    if (image != null)
                    {
                        size = new Size(image.Width, image.Height);
                    }
                    var iconIcon = _icon.ToBitmapSource(size);
                    propertyInfo.SetValue(uiElement, iconIcon);
                }
                else if (propertyInfo.PropertyType == typeof(Icon))
                {
                    // Icon is of type System.Drawing.Icon
                    propertyInfo.SetValue(uiElement, _icon.ToIcon());
                }
                else
                {
                    Log.Error().WriteLine("Unknown type for Icon property: {0}", propertyInfo.PropertyType);
                }
            }