Thursday, February 23, 2012

WPF : Dependency Property Value Precedence

As we know that Dependency properties support value inheritance and can be set from different places which includes Animation, Direct code, based on TemplatedParent, Triggers, There is a precedence involved here which decides what would be value for a particular dependency property if its set from multiple sources.
There precedence is listed below

1. Set by coercion by the property system. This is specified through Metadata while defining a Dependency Property.
2. Set by active animations or held animations, You define animations using storyboard and change value for a particular property using Storyboard.TargetProperty.
3. Set locally by code, by direct setting in XAML, or through data binding, you can set the value by calling DependencyProperty.SetValue or using Binding.
4. Set by TemplatedParent. Within this category is a sub-order of precedence, again listed
in descending order:
a. Set by triggers from the templated parent using, we have 2 types of triggers which are Property Trigeer or Data Trigger and they can set value for properties using Setters in Trigger block.
b. Set by the templated parent through property sets
5. Implicit style; this applies only to the Style property.
6. Set by Style triggers.
7. Set by Template triggers.
8. Set by Style setters.
9. Set by the default Style. There is a sub-order within this category, again listed in descending
order:
a. Set by triggers in the default style
b. Set by setters in the default style
10. Set by inheritance.
11. Set by metadata.

  

No comments:

Post a Comment