#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.