Provides a dependency property identifier for limited write access to a read-only dependency property.
Assembly: WindowsBase (in WindowsBase.dll)
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|OverrideMetadata||Overrides the metadata of a read-only dependency property that is represented by this dependency property identifier.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
The types that register a dependency property can use the in calls to SetValue and ClearValue that adjust the property's value as part of class logic. If permitted by the access level of the key, related classes can use the key and the dependency property also. For instance, you can declare the key as internal, and other types within the same assembly can also set that dependency property.
The returned by read-only dependency property registration should not be made public, because exposing the key makes the property settable, thus defeating the point of registering it as a read-only dependency property. Also, exposing the key causes a mismatch between the available dependency property behaviors and its common language runtime (CLR) property wrapper implementations, which is bad class design.
Instead of exposing the key itself, you should instead expose the DependencyProperty value of the as a public static readonly DependencyProperty on your class. This enables the property to return a valid dependency property identifier for certain property system operations such as enumerating locally set values. However, the identifier thus obtained does not have the full capabilities of a DependencyProperty for many property system operations.
The following example registers a read-only dependency property, and also uses the key for two purposes in other class members: implementing the get "wrapper", and as the identifier for a protected determination operation that sets the value based on calculations of other property values.
Friend Shared ReadOnly AquariumSizeKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("AquariumSize", GetType(Double), GetType(Aquarium), New PropertyMetadata(Double.NaN)) Public Shared ReadOnly AquariumSizeProperty As DependencyProperty = AquariumSizeKey.DependencyProperty Public ReadOnly Property AquariumSize() As Double Get Return CDbl(GetValue(AquariumSizeProperty)) End Get End Property