No, this is NOT another Justin Bieber song…
In the last couple of projects I have consulted on, I have seen VARIOUS implementations of dependency properties… The one thing that I did find interesting is the use of metadata. Some use PropertyMetadata
, others use FrameworkPropertyMetadata
and the Visual Studio snippet uses UIPropertyMetadata
! Which one should I choose?
First, a MSDN recap.
PropertyMetadata
“Defines certain behavior aspects of a dependency property as it is applied to a specific type, including conditions it was registered with.”
UIPropertyMetadata
“Provides property metadata for non-framework properties that do have rendering/user interface impact at the core level. “
FrameworkPropertyMetadata
“Reports or applies metadata for a dependency property, specifically adding framework-specific property system characteristics.”
Does this help? I didn’t think so! Let's try again… PropertyMetadata
offers us default value, a property changed callback and coercion support! UIPropertyMetadata
builds on top of PropertyMetadata
but adds IsAnimationProhibited
… This controls if animation is supported on this property. And last but not the least… we have FrameworkPropertyMetadata
. This adds FrameworkPropertyMetadataOptions
that controls framework-level behaviors like:
None
- No options are specified; the dependency property uses the default behavior of the Windows Presentation Foundation (WPF) property system.
AffectsMeasure
- The measure pass of layout compositions is affected by value changes to this dependency property.
AffectsArrange
- The arrange pass of layout composition is affected by value changes to this dependency property.
AffectsParentMeasure
- The measure pass on the parent element is affected by value changes to this dependency property.
AffectsParentArrange
- The arrange pass on the parent element is affected by value changes to this dependency property.
AffectsRender
- Some aspect of rendering or layout composition (other than measure or arrange) is affected by value changes to this dependency property.
Inherits
- The values of this dependency property are inherited by child elements.
OverridesInheritanceBehavior
- The values of this dependency property span separated trees for purposes of property value inheritance.
NotDataBindable
- Data binding to this dependency property is not allowed.
BindsTwoWayByDefault
- The BindingMode for data bindings on this dependency property defaults to TwoWay.
Journal
- The values of this dependency property should be saved or restored by journaling processes, or when navigating by Uniform resource identifiers (URIs).
SubPropertiesDoNotAffectRender
- The subproperties on the value of this dependency property do not affect any aspect of rendering.
I have seen so many people use FrameworkPropertyMetadata
just to add a default value… This works but does create some issues (like Silverlight compatibility, etc.)…
Also Read
CodeProject