#133 – Where a Dependency Property Gets Its Value

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:

WPF works down the list until it finds a source that provides a value for the property.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

9 Responses to #133 – Where a Dependency Property Gets Its Value

  1. Pingback: Tweets that mention #133 – Where a Dependency Property Gets Its Value « 2,000 Things You Should Know About WPF -- Topsy.com

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

    • Sean says:

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

  3. Pingback: #137 – The Value of the Style Property Comes From One of Three Places « 2,000 Things You Should Know About WPF

  4. Pingback: #148 – Property Values Set Using Expressions Overwrite the Base Value « 2,000 Things You Should Know About WPF

  5. Pingback: #1,040 – An Example of Dependency Property Inheritance | 2,000 Things You Should Know About WPF

  6. Pingback: WPF -styles precedence | A developer's blog

Leave a comment