DependencyPropertyHelper.GetValueSource : Debugging Helper for Dependency Properties

DependencyPropertyHelper.GetValueSource is a great debugging aid in detecting the source of value of a Dependency Property. This is quite useful for WPF developers who might need to figure out the source which provides the current value for the Dependency Property.

The DependencyPropertyHelper.GetValueSource returns a structure ValueSource which has 5 Properties.

  • BaseValueSource
  • IsAnimated
  • IsCoerced
  • IsCurrent
  • IsExpression
DependencyPropertyHelper.GetValueSource(buttonControl,CustomValueProperty)
{System.Windows.ValueSource}
    BaseValueSource: Local
    IsAnimated: false
    IsCoerced: false
    IsCurrent: false
    IsExpression: true

Dependency Property Value Precedence

The value of Dependency Property is calculated in 5 Steps.

  • Calculate the Base Value
  • Evaluate Expression if any
  • Apply Animation if any
  • Coerce Value

The BaseValueSource in the ValueSource structure speficies how the Base Value of the Dependency property is calculated. The base value of Dependency Property is calculated with aid of property value providers. Some ofthe Value Providers in decreasing Order of precedence are

  • Local Value
  • Templated Parent
  • Implicit style
  • Style triggers
  • Template Triggers
  • Style Setters
  • Theme
  • Inheritence
  • Default Value

Once the base value has been determined, the value is then passed through a series of steps depending on how the value is configured. These include Expressions, Animations and coerce callbacks if they are configured. You can follow more details on Dependency Property Value Precedence in the MSDN documentation

The DependencyPropertyHelper.GetValueSource provides an indication on how the current value in Dependency Property has been determined.