A dependency property to an DependencyObject may get its value from various source, the type of sources that the DependencyProperty may get include
Property system coercion. For details on coercion, see Coercion, Animation, and Base Value later in this topic.
Active animations, or animations with a Hold behavior. In order to have any practical effect, an animation of a property must be able to have precedence over the base (unanimated) value, even if that value was set locally. For details, see Coercion, Animation, and Base Value later in this topic.
Local value. A local value might be set through the convenience of the "wrapper" property, which also equates to setting as an attribute or property element in XAML, or by a call to theSetValue API using a property of a specific instance. If you set a local value by using a binding or a resource, these each act in the precedence as if a direct value was set.
TemplatedParent template properties. An element has a TemplatedParent if it was created as part of a template (a ControlTemplate or DataTemplate). For details on when this applies, seeTemplatedParent later in this topic. Within the template, the following precedence applies:
Triggers from the TemplatedParent template.
Property sets (typically through XAML attributes) in the TemplatedParent template.
Implicit style. Applies only to the Style property. The Style property is filled by any style resource with a key that matches the type of that element. That style resource must exist either in the page or the application; lookup for an implicit style resource does not proceed into the themes.
Style triggers. The triggers within styles from page or application (these styles might be either explicit or implicit styles, but not from the default styles, which have lower precedence).
Template triggers. Any trigger from a template within a style, or a directly applied template.
Style setters. Values from a Setter within styles from page or application.
Default (theme) style. For details on when this applies, and how theme styles relate to the templates within theme styles, see Default (Theme) Styles later in this topic. Within a default style, the following order of precedence applies:
Active triggers in the theme style.
Setters in the theme style.
Inheritance. A few dependency properties inherit their values from parent element to child elements, such that they need not be set specifically on each element throughout an application. For details see Property Value Inheritance.
Default value from dependency property metadata. Any given dependency property may have a default value as established by the property system registration of that particular property. Also, derived classes that inherit a dependency property have the option to override that metadata (including the default value) on a per-type basis. See Dependency Property Metadata for more information. Because inheritance is checked before default value, for an inherited property, a parent element default value takes precedence over a child element. Consequently, if an inheritable property is not set anywhere, the default value as specified on the root or parent is used instead of the child element default value.
// GetValueSource // get the value reports various metadata property system characteristics of a specific dependency Property on a particular DependencyObject public static ValueSource GetValueSource(FrameworkElement item, DependencyProperty prop) { // what if the item does not have teh item property if (item == null) throw new ArgumentNullException("item"); if (prop == null) throw new ArgumentNullException("prop"); // we assume if we cannot get MetaData about a particular DependencyProperty from an FrameworkElement, then // the FrameworkElement does not have that particular property if (prop.GetMetadata(item) == null) throw new ArgumentException(string.Format("item does not have Dependency property {0}", prop.Name)); ValueSource valueSource = DependencyPropertyHelper.GetValueSource(item, prop); return valueSource; }
// GetBaseValueSource // get the ValueSource identify the source of a particular dependency value public static BaseValueSource GetBaseValueSource(FrameworkElement item, DependencyProperty prop) { var valueSource = GetValueSource(item, prop); return valueSource.BaseValueSource; }