Example #1
0
 public FrameworkPropertyMetadata(object defaultValue,
                                  PropertyChangedCallback propertyChangedCallback,
                                  CoerceValueCallback coerceValueCallback) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     Initialize();
 }
Example #2
0
        protected virtual void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
        {
            if (baseMetadata == null)
            {
                throw new ArgumentNullException("baseMetadata");
            }

            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            if (_defaultValue == null)
            {
                _defaultValue = baseMetadata._defaultValue;
            }

            if (_propertyChangedCallback == null)
            {
                _propertyChangedCallback = baseMetadata._propertyChangedCallback;
            }

            if (_coerceValueCallback == null)
            {
                _coerceValueCallback = baseMetadata._coerceValueCallback;
            }
        }
 public FrameworkPropertyMetadata(
             PropertyChangedCallback propertyChangedCallback,
             CoerceValueCallback coerceValueCallback)
             : base(propertyChangedCallback)
 {
     this.CoerceValueCallback = coerceValueCallback;
 }
 public UIPropertyMetadata(
             object defaultValue,
             PropertyChangedCallback propertyChangedCallback,
             CoerceValueCallback coerceValueCallback)
             : base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
 }
Example #5
0
 internal FrameworkPropertyMetadata(
     object defaultValue,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback
     ) : base(defaultValue, propertyChangedCallback, coerceValueCallback, null)
 {
 }
Example #6
0
 public FrameworkPropertyMetadata(
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback)
     : base(propertyChangedCallback)
 {
     this.CoerceValueCallback = coerceValueCallback;
 }
Example #7
0
 public PropertyMetadata(MetadataOption options, PropertyChangedCallback propertyChangedCallback = null,
     CoerceValueCallback coerceValueCallback = null)
 {
     Options = options;
     PropertyChanged = propertyChangedCallback;
     CoerceValue = coerceValueCallback;
 }
Example #8
0
 public FrameworkPropertyMetadata(PropertyChangedCallback propertyChangedCallback,
                                  CoerceValueCallback coerceValueCallback) :
     base(propertyChangedCallback)
 {
     Initialize();
     CoerceValueCallback = coerceValueCallback;
 }
 public FunctionalPropertyMetadata(object defaultValue, FunctionalPropertyMetadataOptions flags, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
 {
     DefaultValue = defaultValue;
     PropertyChangedCallback = propertyChangedCallback;
     CoerceValueCallback = coerceValueCallback;
     _flags = flags;
 }
Example #10
0
 public FrameworkPropertyMetadata(
     object defaultValue,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback)
     : base(defaultValue, new PropertyChangedCallback(new PropertyChangeHook(FrameworkPropertyMetadataOptions.None, propertyChangedCallback, coerceValueCallback).OnPropertyChanged))
 {
 }
Example #11
0
 internal static void AssociatePropertyWithCoercionMethod(DependencyProperty dp, CoerceValueCallback coerceValueCallback)
 {
     if (!_dependencyPropertyCoercionMap.ContainsKey(dp))
     {
         _dependencyPropertyCoercionMap[dp] = coerceValueCallback;
     }
 }
 public UIPropertyMetadata(
     object defaultValue,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback)
     : base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
 }
        public static DependencyProperty <TProperty> Property <TOwner, TProperty>(
            [CallerMemberName] string propertyName = null,
            TProperty defaultValue = default(TProperty),
            PropertyChangedCallback propertyChangedCallback = null,
            CoerceValueCallback coerceValueCallback         = null
            )
            where TOwner : DependencyObject
        {
            const string PropertySuffix = "Property";

            if (propertyName.EndsWith(PropertySuffix))
            {
                propertyName = propertyName.Substring(0, propertyName.Length - PropertySuffix.Length);
            }

            return(new DependencyProperty <TProperty>(DependencyProperty.Register(
                                                          propertyName,
                                                          typeof(TProperty),
                                                          typeof(TOwner),
                                                          new PropertyMetadata(
                                                              defaultValue,
                                                              propertyChangedCallback,
                                                              coerceValueCallback
                                                              )
                                                          )));
        }
Example #14
0
        internal protected virtual void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
        {
            // The supplied metadata is merged with the property metadata for
            // the dependency property as it exists on the base owner. Any
            // characteristics that were specified in the original base
            // metadata will persist; only those characteristics that were
            // specifically changed in the new metadata will override the
            // characteristics of the base metadata. Some characteristics such
            // as DefaultValue are replaced if specified in the new metadata.
            // Others, such as PropertyChangedCallback, are combined.
            // Ultimately, the merge behavior depends on the property metadata
            // type being used for the override, so the behavior described here
            // is for the existing property metadata classes used by WPF
            // dependency properties. For details, see Dependency Property
            // Metadata and Framework Property Metadata.
            // Source: https://msdn.microsoft.com/en-us/library/ms597491(v=vs.110).aspx

            if (!_isCoerceValueCallbackSet)
            {
                CoerceValueCallback = baseMetadata.CoerceValueCallback;
            }

            if (!_isDefaultValueSet)
            {
                DefaultValue = baseMetadata.DefaultValue;
            }

            // Merge PropertyChangedCallback delegates
            PropertyChangedCallback = baseMetadata.PropertyChangedCallback + PropertyChangedCallback;
        }
Example #15
0
 /// <summary> Initializes a new instance of the BusinessValueMetadata class with the specified settings and callbacks.
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="validateValueCallback">A reference to a callback that should perform any custom validation of the business value value beyond typical type validation.</param>
 /// <param name="valueChangedCallback">A reference to a handler implementation that the property system will call whenever the effective value of the property changes.</param>
 /// <param name="coerceValueCallback">A reference to a handler implementation will be called whenever the property system calls CoerceValue for the business value.</param>
 public BusinessValueMetadata(IValueSettings settings, ValidateValueCallback validateValueCallback, BusinessValueChangedCallback valueChangedCallback, CoerceValueCallback coerceValueCallback)
 {
     _settings = settings;
     _validateValueCallback = validateValueCallback;
     _valueChangedCallback  = valueChangedCallback;
     _coerceValueCallback   = coerceValueCallback;
 }
Example #16
0
 public PropertyMetadata(object defaultValue = null, PropertyChangedCallback propertyChangedCallback = null, CoerceValueCallback coerceValueCallback = null, bool inherits = false)
 {
     this.DefaultValue = defaultValue;
     this.PropertyChangedCallback = propertyChangedCallback;
     this.CoerceValueCallback = coerceValueCallback;
     this.Inherits = inherits;
 }
Example #17
0
 internal PropertyMetadata(
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback
     )
 {
     PropertyChangedCallback = propertyChangedCallback;
     CoerceValueCallback     = coerceValueCallback;
 }
Example #18
0
 public FrameworkPropertyMetadata(object defaultValue,
                                  FrameworkPropertyMetadataOptions flags,
                                  PropertyChangedCallback propertyChangedCallback,
                                  CoerceValueCallback coerceValueCallback) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     TranslateFlags(flags);
 }
Example #19
0
 /// <summary>
 ///     UI metadata construction
 /// </summary>
 /// <param name="defaultValue">Default value of property</param>
 /// <param name="propertyChangedCallback">Called when the property has been changed</param>
 /// <param name="coerceValueCallback">Called on update of value</param>
 /// <param name="isAnimationProhibited">Should animation be prohibited?</param>
 public UIPropertyMetadata(object defaultValue,
                           PropertyChangedCallback propertyChangedCallback,
                           CoerceValueCallback coerceValueCallback,
                           bool isAnimationProhibited) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     WriteFlag(MetadataFlags.UI_IsAnimationProhibitedID, isAnimationProhibited);
 }
 /// <summary>
 ///     Type meta construction
 /// </summary>
 /// <param name="defaultValue">Default value of property</param>
 /// <param name="propertyChangedCallback">Called when the property has been changed</param>
 /// <param name="coerceValueCallback">Called on update of value</param>
 public PropertyMetadata(object defaultValue,
                         PropertyChangedCallback propertyChangedCallback,
                         CoerceValueCallback coerceValueCallback)
 {
     DefaultValue            = defaultValue;
     PropertyChangedCallback = propertyChangedCallback;
     CoerceValueCallback     = coerceValueCallback;
 }
Example #21
0
 /// <summary> 
 ///     Type meta construction
 /// </summary>
 /// <param name="defaultValue">Default value of property</param>
 /// <param name="propertyChangedCallback">Called when the property has been changed</param> 
 /// <param name="coerceValueCallback">Called on update of value</param>
 public PropertyMetadata(object defaultValue, 
                         PropertyChangedCallback propertyChangedCallback, 
                         CoerceValueCallback coerceValueCallback)
 { 
     DefaultValue = defaultValue;
     PropertyChangedCallback = propertyChangedCallback;
     CoerceValueCallback = coerceValueCallback;
 } 
Example #22
0
 public UIPropertyMetadata(object defaultValue,
                           PropertyChangedCallback propertyChangedCallback,
                           CoerceValueCallback coerceValueCallback,
                           bool isAnimationProhibited)
     : base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     this.isAnimationProhibited = false;
 }
 /// <summary>
 ///     UI metadata construction
 /// </summary>
 /// <param name="defaultValue">Default value of property</param>
 /// <param name="propertyChangedCallback">Called when the property has been changed</param>
 /// <param name="coerceValueCallback">Called on update of value</param>
 /// <param name="isAnimationProhibited">Should animation be prohibited?</param>
 public UIPropertyMetadata(object defaultValue,
                         PropertyChangedCallback propertyChangedCallback,
                         CoerceValueCallback coerceValueCallback,
                         bool isAnimationProhibited) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     WriteFlag(MetadataFlags.UI_IsAnimationProhibitedID, isAnimationProhibited);
 }
 public ColumnPropertyMetadata(string tableColumnName,
                               bool visible,
                               object defaultValue,
                               PropertyChangedCallback propertyChangedCallback,
                               CoerceValueCallback coerceValueCallback)
     : base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
 }
Example #25
0
		public UIPropertyMetadata (object defaultValue,
					   PropertyChangedCallback propertyChangedCallback,
					   CoerceValueCallback coerceValueCallback,
					   bool isAnimationProhibited)
			: base (defaultValue, propertyChangedCallback, coerceValueCallback)
		{
			this.isAnimationProhibited = false;
		}
 public FrameworkPropertyMetadata(object defaultValue = null, PropertyChangedCallback propertyChangedCallback = null, CoerceValueCallback coerceValueCallback = null, bool inherits = false,
     bool affectsMeasure = false, bool affectsArrange = false, bool bindsTwoWayByDefault = false, UpdateSourceTrigger defaultUpdateSourceTrigger = UpdateSourceTrigger.Default)
     : base(defaultValue, propertyChangedCallback, coerceValueCallback, inherits)
 {
     this.AffectsMeasure = affectsMeasure;
     this.AffectsArrange = affectsArrange;
     this.BindsTwoWayByDefault = bindsTwoWayByDefault;
     this.DefaultUpdateSourceTrigger = defaultUpdateSourceTrigger;
 }
 public FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions flags,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback)
     : base(defaultValue, new PropertyChangedCallback(new PropertyChangeHook(flags, propertyChangedCallback, coerceValueCallback).OnPropertyChanged))
 {
     CoerceValueCallback = coerceValueCallback; //Birbilis
 }
        public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
        {
            if (defaultValue == DependencyProperty.UnsetValue)
                throw new ArgumentException ("Cannot initialize property metadata's default value to 'Unset'");

            this.defaultValue = defaultValue;
            this.propertyChangedCallback = propertyChangedCallback;
            this.coerceValueCallback = coerceValueCallback;
        }
Example #29
0
 internal FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions options,
     BackingFieldUpdateCallback backingFieldUpdateCallback,
     CoerceValueCallback coerceValueCallback
     ) : base(defaultValue: defaultValue, propertyChangedCallback: null, coerceValueCallback: coerceValueCallback, backingFieldUpdateCallback: backingFieldUpdateCallback)
 {
     Options = options.WithDefault();
 }
Example #30
0
 internal FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions options,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback
     ) : base(defaultValue, propertyChangedCallback, coerceValueCallback, null)
 {
     Options = options.WithDefault();
 }
Example #31
0
 internal FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions options,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback,
     BackingFieldUpdateCallback backingFieldUpdateCallback
     ) : base(defaultValue, propertyChangedCallback, coerceValueCallback, backingFieldUpdateCallback)
 {
     Options = options;
 }
Example #32
0
 public FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions flags,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback,
     bool isAnimationProhibited)
     : base(defaultValue, propertyChangedCallback, coerceValueCallback, isAnimationProhibited)
 {
     this.LoadFlags(flags);
 }
        public CoercedDependencyPropertyValueEntry(IDependencyPropertyValueEntry source, DependencyObject dependencyObject, CoerceValueCallback coerceValueCallback)
        {
            this.source = source;

            observableValue = new ObservableValue();
            observableValue.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);
            observableValue.Value = source.Value;

            source.ValueChanged += (sender, e) => observableValue.Value = coerceValueCallback(dependencyObject, source.Value);
        }
Example #34
0
 public PropertyMetadata(
             object defaultValue,
             PropertyChangedCallback propertyChangedCallback,
             CoerceValueCallback coerceValueCallback)
 {
     this.CheckNotUnset(defaultValue);
     this.defaultValue = defaultValue;
     this.propertyChangedCallback = propertyChangedCallback;
     this.coerceValueCallback = coerceValueCallback;
 }
Example #35
0
 public PropertyMetadata(
     object defaultValue,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback)
 {
     this.CheckNotUnset(defaultValue);
     this.defaultValue            = defaultValue;
     this.propertyChangedCallback = propertyChangedCallback;
     this.coerceValueCallback     = coerceValueCallback;
 }
Example #36
0
        private static object DoCoercion(DependencyObject d, DependencyProperty dp, CoerceValueCallback coerceValueCallback, object defaultBaseValue, bool forceNewBaseValue, out bool isReentrantImplicitCoercion)
        {
            // get the current property value
            object effectiveValue = d.GetValue(dp);

            CoercionData        cd;
            CoercedPropertyInfo cpi;

            EnsureCoercionDataForProperty(d, dp, defaultBaseValue, out cd, out cpi);

            // note whether this is a reentrant call to implicitly coerce the property
            isReentrantImplicitCoercion = (cpi.IsCoercingValue && !cpi.IsExplicitCoercion);

            // avoid reentrancy during value coercion
            if (!cpi.IsCoercingValue)
            {
                if (forceNewBaseValue)
                {
                    cpi.BaseValue = defaultBaseValue;
                }

                object baseValue    = cpi.BaseValue;
                object coercedValue = baseValue;
                cpi.IsCoercingValue = true;
                try
                {
                    // coerce the value
                    coercedValue = coerceValueCallback(d, baseValue);

                    // if the coerced value is different from the effective value, update the property
                    if (effectiveValue == null ? coercedValue != null : !effectiveValue.Equals(coercedValue))
                    {
                        d.SetValue(dp, coercedValue);
                        effectiveValue = coercedValue;
                    }
                }
                finally
                {
                    cpi.IsCoercingValue = false;
                }

                // if setting a new base value and the coerced value equals that base value, there is no need to store it
                if (forceNewBaseValue && (baseValue == null ? coercedValue != null : !baseValue.Equals(coercedValue)))
                {
                    cd.Remove(dp);
                    if (cd.Count == 0)
                    {
                        d.ClearValue(CoercionDataProperty);
                    }
                }
            }

            // return the effective property value
            return(effectiveValue);
        }
        private static object CoerceIsChecked(DependencyObject sender, object value, CoerceValueCallback originalCallback)
        {
            if (sender is MenuItem menuItem &&
                menuItem.Command is ICommand command &&
                !command.CanExecute(menuItem.CommandParameter))
            {
                return(menuItem.IsChecked);
            }

            return(value);
        }
Example #38
0
        public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
        {
            if (defaultValue == DependencyProperty.UnsetValue)
            {
                throw new ArgumentException("Cannot initialize property metadata's default value to 'Unset'");
            }

            this.defaultValue            = defaultValue;
            this.propertyChangedCallback = propertyChangedCallback;
            this.coerceValueCallback     = coerceValueCallback;
        }
Example #39
0
 internal FrameworkPropertyMetadata(
     object defaultValue,
     FrameworkPropertyMetadataOptions options,
     PropertyChangedCallback propertyChangedCallback,
     CoerceValueCallback coerceValueCallback,
     UpdateSourceTrigger defaultUpdateSourceTrigger
     ) : base(defaultValue, propertyChangedCallback, coerceValueCallback, null)
 {
     Options = options.WithDefault();
     DefaultUpdateSourceTrigger = defaultUpdateSourceTrigger;
 }
Example #40
0
        public static CoerceValueCallback CreateCoerceValueCallback <TPROP>(Func <object, TPROP> coerceValue)
        {
            CoerceValueCallback callback = null;

            if (coerceValue != null)
            {
                callback = new CoerceValueCallback((o, p) => { return(coerceValue(p)); });
            }

            return(callback);
        }
Example #41
0
            internal static CoerceValueCallback GetValueCoercionCallback(Type ownerType, string methodName)
            {
                CoerceValueCallback result = null;
                Dictionary <string, CoerceValueCallback> coercionMethodsForType;

                if (_knownValueCoercionMethods.TryGetValue(ownerType, out coercionMethodsForType))
                {
                    coercionMethodsForType.TryGetValue(methodName, out result);
                }
                return(result);
            }
Example #42
0
        public CoercedDependencyPropertyValueEntry(IDependencyPropertyValueEntry source, DependencyObject dependencyObject, CoerceValueCallback coerceValueCallback)
        {
            this.source              = source;
            this.dependencyObject    = dependencyObject;
            this.coerceValueCallback = coerceValueCallback;

            observableValue = new ObservableValue();
            observableValue.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);

            source.ValueChanged += (sender, e) => CoerceValue();
            CoerceValue();
        }
Example #43
0
		public RibbonMenuItemView()
		{
			DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(RibbonMenuItemView.IsSelectedProperty, typeof(RibbonMenuItemView));
			if (dpd != null)
			{
				_callback = dpd.DesignerCoerceValueCallback;
				dpd.DesignerCoerceValueCallback = new CoerceValueCallback(CoerceValueCallback);
				dpd.AddValueChanged(this, (s, e) =>
				{
					var item = s as RibbonMenuItemView;
					if (item != null && item.IsSelected && !item.HasContent)
						item.IsSelected = false;
				});
			}
			AddHandler(Button.ClickEvent, (RoutedEventHandler)Click);
		}
 internal IndependentlyAnimatedPropertyMetadata(object defaultValue, 
     PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback) 
     : base(defaultValue, propertyChangedCallback, coerceValueCallback) {}
 public FrameworkPropertyMetadata(Object defaultValue, FrameworkPropertyMetadataOptions flags, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback, bool isAnimationProhibited)
 {
 }
 public FrameworkPropertyMetadata(Object defaultValue, FrameworkPropertyMetadataOptions flags, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback, bool isAnimationProhibited, System.Windows.Data.UpdateSourceTrigger defaultUpdateSourceTrigger)
 {
 }
Example #47
0
        internal static DependencyProperty RegisterProperty(
            string name,
            Type propertyType,
            Type ownerType,
            object defaultValue,
            PropertyChangedCallback changed,
            ValidateValueCallback validate,
            bool isIndependentlyAnimated,
            CoerceValueCallback coerced)
        {
            // Override metadata for this particular object type. This defines
            // the methods that will be called when property actions (setting,
            // getting, invalidating) are taken for this specific object type.

            UIPropertyMetadata propertyMetadata;

            // If this property is animated using a property resource, we create
            // AnimatablePropertyMetadata instead of UIPropertyMetadata.

            if (isIndependentlyAnimated)
            {
                propertyMetadata = new IndependentlyAnimatedPropertyMetadata(defaultValue);
            }
            else
            {
                propertyMetadata = new UIPropertyMetadata(defaultValue);
            }

            propertyMetadata.PropertyChangedCallback = changed;

            if (coerced != null)
            {
                propertyMetadata.CoerceValueCallback = coerced;
            }

            // Register property with passed in default metadata.  The type of
            // defaultMetadata will determine whether this property is animatable.
            DependencyProperty dp = DependencyProperty.Register(
                name,
                propertyType,
                ownerType,
                propertyMetadata,
                validate);

            return dp;
        }
 public FrameworkPropertyMetadata(object defaultValue,
                                  FrameworkPropertyMetadataOptions flags,
                                  PropertyChangedCallback propertyChangedCallback,
                                  CoerceValueCallback coerceValueCallback,
                                  bool isAnimationProhibited) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback, isAnimationProhibited)
 {
     TranslateFlags(flags);
 }
 public FunctionalPropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
     : this(defaultValue, FunctionalPropertyMetadataOptions.None, propertyChangedCallback, coerceValueCallback)
 {
 }
 public FunctionalPropertyMetadata(PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
     : this(null, FunctionalPropertyMetadataOptions.None, propertyChangedCallback, coerceValueCallback)
 {
 }
Example #51
0
        protected virtual void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
        {
            if (baseMetadata == null)
                throw new ArgumentNullException("baseMetadata");

            if (dp == null)
                throw new ArgumentNullException("dp");

            if (_defaultValue == null)
                _defaultValue = baseMetadata._defaultValue;

            if (_propertyChangedCallback == null)
                _propertyChangedCallback = baseMetadata._propertyChangedCallback;

            if (_coerceValueCallback == null)
                _coerceValueCallback = baseMetadata._coerceValueCallback;
        }
Example #52
0
 public PropertyMetadata(MetadataOption options, CoerceValueCallback coerceValueCallback)
     : this(options, null, coerceValueCallback)
 {
 }
 public FrameworkPropertyMetadata(PropertyChangedCallback propertyChangedCallback,
                                     CoerceValueCallback coerceValueCallback) :
     base(propertyChangedCallback)
 {
     Initialize();
     CoerceValueCallback = coerceValueCallback;
 }
 internal void Merge(PropertyMetadata baseMetadata, DependencyProperty dp)
 {
     CheckFrozen();
     if (_DefaultValue == null)
         _DefaultValue = baseMetadata._DefaultValue;
     if (_PropertyChangedCallback == null)
         _PropertyChangedCallback = baseMetadata._PropertyChangedCallback;
     if (_CoerceValueCallback == null)
         _CoerceValueCallback = baseMetadata._CoerceValueCallback;
     OnMerge(baseMetadata, dp);
 }
Example #55
0
        private void ProcessCoerceValue(
            DependencyProperty dp, 
            PropertyMetadata metadata,
            ref EntryIndex entryIndex,
            ref int targetIndex,
            ref EffectiveValueEntry newEntry, 
            ref EffectiveValueEntry oldEntry,
            ref object oldValue, 
            object baseValue, 
            object controlValue,
            CoerceValueCallback coerceValueCallback, 
            bool coerceWithDeferredReference,
            bool coerceWithCurrentValue,
            bool skipBaseValueChecks)
        { 
            if (newEntry.IsDeferredReference)
            { 
                Debug.Assert(!(newEntry.IsCoerced && !newEntry.IsCoercedWithCurrentValue) && 
                    !newEntry.IsAnimated, "Coerced or Animated value cannot be a deferred reference");
 
                // Allow values to stay deferred through coercion callbacks in
                // limited circumstances, when we know the listener is internal.
                // Since we never assign DeferredReference instances to
                // non-internal (non-friend assembly) classes, it's safe to skip 
                // the dereference if the callback is to the DP owner (and not
                // a derived type).  This is consistent with passing raw 
                // DeferredReference instances to ValidateValue callbacks, which 
                // only ever go to the owner class.
                if (!coerceWithDeferredReference || 
                    dp.OwnerType != metadata.CoerceValueCallback.Method.DeclaringType) // Need 2nd check to rule out derived class callback overrides.
                {
                    // Resolve deferred references because we need the actual
                    // baseValue to evaluate the correct animated value. This is done 
                    // by invoking GetValue for this property.
                    DeferredReference dr = (DeferredReference) baseValue; 
                    baseValue = dr.GetValue(newEntry.BaseValueSourceInternal); 

                    // Set the baseValue back into the entry 
                    newEntry.SetCoersionBaseValue(baseValue);

                    entryIndex = CheckEntryIndex(entryIndex, targetIndex);
                } 
            }
 
            object coercedValue = coerceWithCurrentValue ? controlValue : coerceValueCallback(this, baseValue); 

            // Make sure that the call out did not cause a change to entryIndex 
            entryIndex = CheckEntryIndex(entryIndex, targetIndex);

            // Even if we used the controlValue in the coerce callback, we still want to compare against the original baseValue
            // to determine if we need to set a coerced value. 
            if (!Equals(dp, coercedValue, baseValue))
            { 
                // returning DependencyProperty.UnsetValue from a Coercion callback means "don't do the set" ... 
                // or "use previous value"
                if (coercedValue == DependencyProperty.UnsetValue) 
                {
                    if (oldEntry.IsDeferredReference)
                    {
                        DeferredReference reference = (DeferredReference)oldValue; 
                        oldValue = reference.GetValue(oldEntry.BaseValueSourceInternal);
 
                        entryIndex = CheckEntryIndex(entryIndex, targetIndex); 
                    }
 
                    coercedValue = oldValue;
                }

                // Note that we do not support the value being coerced to a 
                // DeferredReference
                if (!dp.IsValidValue(coercedValue)) 
                { 
                    // well... unless it's the control's "current value"
                    if (!(coerceWithCurrentValue && coercedValue is DeferredReference)) 
                        throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, coercedValue, dp.Name));
                }

                // Set the coerced value here. All other values would 
                // have been set during EvaluateEffectiveValue/GetValueCore.
 
                newEntry.SetCoercedValue(coercedValue, baseValue, skipBaseValueChecks, coerceWithCurrentValue); 
            }
        } 
 public FrameworkPropertyMetadata(Object defaultValue, PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
 {
 }
 public FrameworkPropertyMetadata(object defaultValue,
                         PropertyChangedCallback propertyChangedCallback,
                         CoerceValueCallback coerceValueCallback) :
     base(defaultValue, propertyChangedCallback, coerceValueCallback)
 {
     Initialize();
 }
 public FrameworkPropertyMetadata(PropertyChangedCallback propertyChangedCallback, CoerceValueCallback coerceValueCallback)
 {
 }
        public FrameworkPropertyMetadata(object defaultValue,
                                         FrameworkPropertyMetadataOptions flags,
                                         PropertyChangedCallback propertyChangedCallback,
                                         CoerceValueCallback coerceValueCallback,
                                         bool isAnimationProhibited,
                                         UpdateSourceTrigger defaultUpdateSourceTrigger) :
            base(defaultValue, propertyChangedCallback, coerceValueCallback, isAnimationProhibited)
        {
            if (!BindingOperations.IsValidUpdateSourceTrigger(defaultUpdateSourceTrigger))
                throw new InvalidEnumArgumentException("defaultUpdateSourceTrigger", (int) defaultUpdateSourceTrigger, typeof(UpdateSourceTrigger));
            if (defaultUpdateSourceTrigger == UpdateSourceTrigger.Default)
                throw new ArgumentException(SR.Get(SRID.NoDefaultUpdateSourceTrigger), "defaultUpdateSourceTrigger");

            TranslateFlags(flags);
            DefaultUpdateSourceTrigger = defaultUpdateSourceTrigger;
        }
Example #60
0
		protected virtual void Merge (PropertyMetadata baseMetadata, DependencyProperty dp)
		{
			if (defaultValue == null)
				defaultValue = baseMetadata.defaultValue;
			if (propertyChangedCallback == null)
				propertyChangedCallback = baseMetadata.propertyChangedCallback;
			if (coerceValueCallback == null)
				coerceValueCallback = baseMetadata.coerceValueCallback;
		}