December 03, 2013
Represents a dependency property that is registered with the Windows Phone dependency property system. Dependency properties provide support for value expressions, data binding, animation, and property change notification.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<object property="dependencyPropertyName"/> - or - <object property="ownerTypeName.dependencyPropertyName"/> - or - <object property="attachedPropertyOwnerTypeName.attachedPropertyName"/>
A shorthand for remembering the above syntax, so long as XAML namespace mapping is not required, is to use the name of the dependency property identifier field, but subtracting the suffix Property.
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetMetadata||Retrieves the property metadata value for the dependency property as registered to the specified Type.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Register||Registers a dependency property with the specified property name, property type, owner type, and property metadata for the property.|
|RegisterAttached||Registers an attached dependency property with the specified property name, property type, owner type, and property metadata for the property.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Dependency property concepts are covered in detail in the topic Dependency properties for Windows Phone.
Instances of are often referenced in the documentation as dependency property identifiers. The identifiers provide a way to refer to a dependency property that was registered to a particular DependencyObject owner type. When the owner type registers the property, the owner type exposes the instance as the identifier. The owner DependencyObject provides the property store for the dependency property as it participates in the Windows Phone property system.
When working with a dependency property in code, you might use a identifier as input for calls to property system methods such as SetValue. However, in most cases, getting or setting a dependency property is simpler by getting or setting the "wrapper" CLR property that generally exposes the dependency property to XAML usage and to the CLR type system. For details, see "Dependency Properties Back CLR Properties" section of Dependency properties for Windows Phone.
supports a native conversion for XAML attribute syntax for filling values, which is used when a Setter specifies its Property value. This conversion uses an ownerTypeName.propertyName form for the input string.
A related type that can also be used to specify a property by name and is required by certain data and animation APIs is PropertyPath. A PropertyPath can be used to reference any CLR property (that property can also be a dependency property, but does not have to be). A PropertyPath can be specified in XAML, and can be used to specify a property within an object hierarchy.
The Windows Phone property system supports its implementation of the XAML attached property language feature with identifiers and property storage on a DependencyObject..
Custom Dependency Properties
If you want properties on your custom types to support value expressions, data binding, or animation, you should back these CLR properties with a dependency property following these guidelines:
Register a dependency property using the Register method, which returns a . You should store as an accessible static read-only field in your class. By convention, the name of this identifier field should end with Property.
During registration, you can provide PropertyMetadata for the property to further define the property's behaviors.
Provide CLR get and set accessors for the property.
The following example shows a basic usage where a is established as a public static member of a class. This is done by calling Register and storing the return value.