DependencyPropertyKey.DependencyProperty Property

Gets the dependency property identifier associated with this specialized read-only dependency property identifier.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

public DependencyProperty DependencyProperty { get; }

Property Value

Type: System.Windows.DependencyProperty
The relevant dependency property identifier.

The DependencyProperty value enables a read-only property's identifier to participate in common property system operations using some of the same interfaces as used for read-write dependency properties.

In order to implement the get property accessor for a read-only dependency property, you should create and expose a DependencyProperty identifier on your class. This serves two purposes:

  • Your own class needs the DependencyProperty identifier in order to implement the get accessor for the property wrapper. You use the DependencyProperty as a parameter for the GetValue call that implements the get accessor.

  • DependencyProperty identifiers expose your dependency property to the property system such that other methods that rely on metadata can access it in a standard form. For instance, if you called GetLocalValueEnumerator on some DependencyObject and obtained an enumeration of locally set properties (values and identifiers) the identifier returned for a read-only dependency property would be your DependencyProperty value rather than the key. Not exposing a DependencyProperty identifier does not increase the security of your read-only dependency property in any way, it just makes operations that involve your property more awkward both for subsequent derived classes and class instances.

To expose the DependencyProperty identifier on your class, you call DependencyProperty directly on your key. Use this value to create a public static readonly DependencyProperty identifier on the class, which parallels the DependencyPropertyKey.

The following example calls DependencyProperty to expose the DependencyProperty identifier (AquariumGraphicProperty) for the AquariumGraphic read-only dependency property on a class. The example also shows the DependencyPropertyKey creation (as an internal member) and the get accessor for AquariumGraphic.

internal static readonly DependencyPropertyKey AquariumSizeKey = DependencyProperty.RegisterReadOnly(
  "AquariumSize",
  typeof(double),
  typeof(Aquarium),
  new PropertyMetadata(double.NaN)
);
public static readonly DependencyProperty AquariumSizeProperty =
  AquariumSizeKey.DependencyProperty;
public double AquariumSize
{
  get { return (double)GetValue(AquariumSizeProperty); }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft