Пример #1
0
        private static PropertyChangedCallback WrapFrameworkFlagsCallback(PropertyChangedCallback propertyChangedCallback, FrameworkPropertyMetadataOptionsXm flags)
        {
            return(delegate(DependencyObject o, DependencyPropertyChangedEventArgs args)
            {
                if (o is UIElement uie)
                {
                    if ((flags & FrameworkPropertyMetadataOptionsXm.AffectsMeasure) != 0)
                    {
                        uie.InvalidateMeasure();
                    }

                    if ((flags & FrameworkPropertyMetadataOptionsXm.AffectsArrange) != 0)
                    {
                        uie.InvalidateArrange();
                    }

                    if (VisualTreeHelper.GetParent(uie) is UIElement parent)
                    {
                        if ((flags & FrameworkPropertyMetadataOptionsXm.AffectsParentMeasure) != 0)
                        {
                            parent.InvalidateMeasure();
                        }

                        if ((flags & FrameworkPropertyMetadataOptionsXm.AffectsParentArrange) != 0)
                        {
                            parent.InvalidateArrange();
                        }
                    }
                }

                propertyChangedCallback?.Invoke(o, args);
            });
        }
Пример #2
0
        private static PropertyChangedCallback WrapCoerceCallback(PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
        {
            if (propertyChangedCallback == null && coerceValueCallback == null)
            {
                return(null);
            }

            if (coerceValueCallback == null)
            {
                return(propertyChangedCallback);
            }

            var exception = false;

            return(delegate(DependencyObject o, DependencyPropertyChangedEventArgs args)
            {
                if (CoercionService.EnterCoercion(o, args) == false)
                {
                    return;
                }

                try
                {
                    var coercedValue = args.NewValue;

                    coercedValue = coerceValueCallback(o, coercedValue);

                    if (Equals(args.NewValue, coercedValue) == false)
                    {
                        o.SetValue(args.Property, args.OldValue);
                        o.SetValue(args.Property, coercedValue);
                    }
                }
                catch (Exception ex)
                {
                    o.SetValue(args.Property, args.OldValue);

                    exception = true;

                    throw new InvalidOperationException("An error occurred while handling property change. See the inner exception for details", ex);
                }
                finally
                {
                    var coerceState = CoercionService.LeaveCoercion(o, args);

                    if (exception == false)
                    {
                        if (Equals(args.OldValue, coerceState.CoercedValueEventArgs.NewValue) == false)
                        {
                            propertyChangedCallback?.Invoke(o, coerceState.CoercedValueEventArgs);
                        }
                    }
                }
            });
        }
Пример #3
0
        public DependencyPropertyKey RegisterReadOnlyProperty <T>(
            string name,
            T defaultValue = default(T),
            PropertyChangedCallback propertyChanged = null)
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(
                defaultValue,
                (d, e) => propertyChanged?.Invoke((TOwner)d, e));

            return(DependencyProperty.RegisterReadOnly(name, typeof(T), typeof(TOwner), metadata));
        }
Пример #4
0
    private void InternalCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        if (DrawingPropertyChanged != null)
        {
            DrawingPropertyChangedEventArgs args = new DrawingPropertyChangedEventArgs
            {
                Metadata   = this,
                IsAnimated = DependencyPropertyHelper.GetValueSource(sender, e.Property).IsAnimated
            };
            DrawingPropertyChanged(sender, args);
        }

        propertyChangedCallback?.Invoke(sender, e);
    }
Пример #5
0
        public DependencyProperty RegisterProperty <T>(
            string name,
            T defaultValue,
            FrameworkPropertyMetadataOptions flags,
            PropertyChangedCallback propertyChanged = null,
            CoerceValueCallback coerceValue         = null)
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(
                defaultValue,
                flags,
                (d, e) => propertyChanged?.Invoke((TOwner)d, e),
                (d, e) => coerceValue?.Invoke(d, e));

            return(DependencyProperty.Register(name, typeof(T), typeof(TOwner), metadata));
        }
Пример #6
0
        protected void Set <T>(ref T field, T value, PropertyChangedCallback <T> callback, [CallerMemberName] string propertyName = null)
        {
            if (!System.Collections.Generic.EqualityComparer <T> .Default.Equals(field, value))
            {
                OnPropertyChanging(propertyName);

                T oldValue = field;

                field = value;

                OnPropertyChanged(propertyName);

                callback?.Invoke(oldValue, value);
            }
        }
Пример #7
0
    public static DependencyProperty RegisterDependencyProperty <TView, TProperty>(
        Expression <Func <TView, TProperty> > property,
        TProperty defaultValue, PropertyChangedCallback <TView, TProperty> propertyChangedCallback)
        where TView : DependencyObject
    {
        var expression   = (MemberExpression)property.Body;
        var propertyName = expression.Member.Name;

        PropertyChangedCallback callback = (d, e) =>
        {
            DependencyPropertyChangedEventArgs <TProperty> eArgs =
                new DependencyPropertyChangedEventArgs <TProperty>(e.Property, (TProperty)e.OldValue, (TProperty)e.NewValue);

            propertyChangedCallback?.Invoke((TView)d, eArgs);
        };

        return(DependencyProperty.Register(
                   propertyName,
                   typeof(TProperty),
                   typeof(TView),
                   new PropertyMetadata(defaultValue, callback)
                   ));
    }
Пример #8
0
 private void OnOffsetChanged(float x, float y)
 {
     OnPropertyChanged?.Invoke(this);
 }
 internal void InvokePropertyChangedCallback(NotifyPropertyChanged sender, PropertyChangedCallbackArgs e)
 {
     PropertyChangedCallback?.Invoke(sender, e);
 }
Пример #10
0
 public void RaisePropertyChanged(string interfaceName, string propertyName, object newValue, ObjectPath path)
 {
     PropertyChangedCallback?.Invoke(interfaceName, new Dictionary <string, object> {
         { propertyName, newValue }
     }, new string[0], path);
 }
Пример #11
0
 internal void RaisePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
 {
     PropertyChangedCallback?.Invoke(source, e);
 }