I know the basic difference among these classes that PropertyMetadata is used when we backup property, UIPropertyMetadata when we want to have support for animation, and FrameworkMetadata for Framework properties to be used in user controls.
But I understand theoretical part only. It will be a great hep if you please explain a simplest example that uses all these 3 classes in 3 different dependency properties distinguishing them clearly.
Thanks in advance.
Source: PropertyMetadata vs. FrameworkPropertyMetadata
When you implement a custom dependency property and you register the property by calling
DependencyProperty.Register
, you specify some metadata for the property by passing it an instance ofPropertyMetadata
. This can be an instance of thePropertyMetadata
class or an instance of one of its subclasses. The differences are shown below.
PropertyMetadata
– Basic metadata relating to dependency properties
CoerceValueCallback
– coerce the value when being setDefaultValue
– a default value for the propertyPropertyChangedCallback
– respond to new effective value for the property
UIPropertyMetadata
– derives fromPropertyMetadata
and adds:
IsAnimationProhibited
– disable animations for this property?
FrameworkPropertyMetadata
– derives fromUIPropertyMetadata
and adds:
AffectsArrange
,AffectsMeasure
,AffectsParentArrange
,AffectsParentMeasure
,AffectsRender
– Should layout calculations be re-run after property value changes?BindsTwoWayByDefault
,DefaultUpdateSourceTrigger
,IsDataBindingAllowed
,IsNotDataBindable
– Dictates how property participates in data bindingInherits
,OverridesInheritanceBehavior
– Does inheritance work for this property?Journal
– Store this value when journaling?SubPropertiesDoNotAffectRender
– Check properties of this object when layout changes?
An important practical difference between PropertyMetadata and FrameworkPropertyMetadata is that the latter allows to specify a set of FrameworkPropertyMetadataOptions.
For example, specifying FrameworkPropertyMetadataOptions.AffectsRender
cares for initiating a re-rendering of a UIElement on which the property has changed. Without this flag you would have to do that manually in a PropertyChangedCallback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With