#133 – Where a Dependency Property Gets Its Value
November 22, 2010 9 Comments
Since the value of a dependency property can come from a variety of different sources, WPF uses a predetermined precedence for each possible source of a property value in order to determine the final value.
WPF determines the final value for a dependency property as follows:
- Determine the base value, using the precedence rules listed below
- Evaluate expressions
- Apply animations
- Coerce value (implementing class might coerce to valid value)
- Validate (implementing class may throw exception if value is invalid)
The base value of a property is obtained from one of the following sources, listed from highest to lowest precedence:
- Local value (set in code or XAML)
- Parent template trigger
- Parent template
- Implicit style (for Style property)
- Style triggers
- Template triggers
- Style setters
- Theme style triggers
- Theme style
- Inheritance
- Default value
WPF works down the list until it finds a source that provides a value for the property.
Pingback: Tweets that mention #133 – Where a Dependency Property Gets Its Value « 2,000 Things You Should Know About WPF -- Topsy.com
Of the top of my head I know that animation comes before local value (I.e. At the top). That is the only way animations would run on a local value 🙂
You might want to double check these bro http://msdn.microsoft.com/en-us/library/ms743230.aspx
You’re right–property values set via animations take precedence over those set as local values. I think that this is reflected correctly in the post, as follows. If you’ve set a local value and then apply an animation, the local value takes precedence when determining the base value (see list of base values). Then after calculating the base value, animations are applied, overwriting the base value (see first bullet list).
Ahhh…sorry I missed that 🙂 great post. I haven’t seen it explained like this elsewhere. Appreciate the innovation 🙂
Thanks!
Pingback: #137 – The Value of the Style Property Comes From One of Three Places « 2,000 Things You Should Know About WPF
Pingback: #148 – Property Values Set Using Expressions Overwrite the Base Value « 2,000 Things You Should Know About WPF
Pingback: #1,040 – An Example of Dependency Property Inheritance | 2,000 Things You Should Know About WPF
Pingback: WPF -styles precedence | A developer's blog