DependencyProperty.RegisterAttachedReadOnly Method (String, Type, Type, PropertyMetadata)
Registers a read-only , with the specified property type, owner type, and property metadata. GTMT
Assembly: WindowsBase (in WindowsBase.dll)
public static DependencyPropertyKey RegisterAttachedReadOnly( string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata )
The name of the dependency property to register.
The type of the property.
The owner type that is registering the dependency property.
Property metadata for the dependency property.
Return ValueType: System.Windows.DependencyPropertyKey
A dependency property key that should be used to set the value of a static read-only field in your class, which is then used to reference the dependency property later.
This method returns the type DependencyPropertyKey, whereas RegisterAttached returns the type DependencyProperty. Typically, the keys that represent read-only properties are not made public, because the keys can be used to set the dependency property value by calling SetValue(DependencyPropertyKey, Object). Your class design will affect your requirements, but it is generally recommended to limit the access and visibility of any DependencyPropertyKey to only those parts of your code that are necessary to set that dependency property as part of class or application logic. It is also recommended that you expose a dependency property identifier for the read-only dependency property, by exposing the value of DependencyPropertyKey.DependencyProperty as a public static readonly field on your class.
Read-only attached properties are a rare scenario, because the primary scenario for an attached property is its use in XAML. Without a public setter, an attached property cannot be set in XAML syntax.
For more information on dependency property registration, see DependencyProperty.
One particular scenario for registering a dependency property as attached is to support property value inheritance. You should register value-inheriting dependency properties with RegisterAttached even if the class defines property wrapper accessors that expose the dependency property, and even if you do not intend to expose Get* and Set* static methods to provide true attached property support accessors. Although property value inheritance might appear to work for nonattached dependency properties, the inheritance behavior for a nonattached property through certain element boundaries in the runtime tree is undefined. Registering the property as attached effectively makes the attached property a global property to the property system, and assures that property value inheritance works across all boundaries in an element tree. Always use RegisterAttached to register properties where you specify Inherits in the metadata. For more information, see Property Value Inheritance.
Available since 3.0