Click here to Skip to main content
15,888,521 members
Articles / All Topics

Eeny, Meeny, Miny, Moe

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
27 Aug 2010CPOL2 min read 8.3K   1  
I have seen VARIOUS implementations of dependency properties… which one should I choose?

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

This article was originally posted at http://www.rudigrobler.net:80/Blog/eeny-meeny-miny-moe

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --