Esporta (0) Stampa
Espandi tutto

Proprietà DependencyPropertyKey.DependencyProperty

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

Spazio dei nomi: System.Windows
Assembly: WindowsBase (in windowsbase.dll)
Spazio dei nomi XML:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public DependencyProperty DependencyProperty { get; }
/** @property */
public DependencyProperty get_DependencyProperty ()

public function get DependencyProperty () : DependencyProperty

Non è possibile utilizzare questa proprietà in XAML.

Valore proprietà

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 readonlyDependencyProperty 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); }
}

Microsoft .NET Framework 3.0 è supportato in Windows Vista, Microsoft Windows XP SP2 e Windows Server 2003 SP1.

.NET Framework

Supportato in:

Aggiunte alla community

AGGIUNGI
Mostra:
© 2014 Microsoft