DependencyPropertyKey.DependencyProperty プロパティ

定義

この特殊な読み取り専用依存関係プロパティ識別子に関連付けられている依存関係プロパティ識別子を取得します。

public:
 property System::Windows::DependencyProperty ^ DependencyProperty { System::Windows::DependencyProperty ^ get(); };
public System.Windows.DependencyProperty DependencyProperty { get; }
member this.DependencyProperty : System.Windows.DependencyProperty
Public ReadOnly Property DependencyProperty As DependencyProperty

プロパティ値

関連する依存関係プロパティ識別子。

次の例では、 を呼び出DependencyPropertyして、DependencyPropertyクラスの読み取り専用依存関係プロパティのAquariumGraphic識別子 (AquariumGraphicProperty) を公開します。 この例では、 の DependencyPropertyKey 作成 (内部メンバーとして) と get アクセサー 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); }
}
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

注釈

DependencyProperty を使用すると、読み取り専用プロパティの識別子は、読み取り/書き込み依存関係プロパティに使用されるのと同じインターフェイスの一部を使用して、一般的なプロパティ システム操作に参加できます。

読み取り専用の依存関係プロパティの get プロパティ アクセサーを実装するには、クラスに識別子を DependencyProperty 作成して公開する必要があります。 これは、次の 2 つの目的があります。

  • プロパティ ラッパーの get アクセサーを DependencyProperty 実装するには、独自のクラスに識別子が必要です。 get アクセサーを実装する呼び出しのGetValueパラメーターとして を使用DependencyPropertyします。

  • DependencyProperty 識別子は、メタデータに依存する他のメソッドが標準形式でアクセスできるように、依存関係プロパティをプロパティ システムに公開します。 たとえば、 をDependencyObject呼び出GetLocalValueEnumeratorし、ローカルに設定されたプロパティ (値と識別子) の列挙を取得した場合、読み取り専用の依存関係プロパティに対して返される識別子は、キーではなく値DependencyPropertyになります。 識別子を DependencyProperty 公開しないと、読み取り専用の依存関係プロパティのセキュリティが向上するわけではありません。これにより、後続の派生クラスとクラス インスタンスの両方で、プロパティを含む操作がより厄介になります。

クラスの識別子を DependencyProperty 公開するには、キーで 直接 を呼び出 DependencyProperty します。 この値を使用して、 public static readonlyDependencyProperty クラスに識別子を作成します。これは、 と並行しています DependencyPropertyKey

適用対象

こちらもご覧ください