다음을 통해 공유


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 호출하여 클래스의 AquariumGraphic 읽기 전용 종속성 속성에 대한 DependencyProperty 식별자(AquariumGraphicProperty)를 노출합니다. 또한 이 예제에서는 DependencyPropertyKey 만들기(내부 멤버)와 AquariumGraphic대한 get 접근자를 보여 줍니다.

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 식별자를 만들고 노출해야 합니다. 이는 다음 두 가지 용도로 사용됩니다.

  • 속성 래퍼에 대한 get 접근자를 구현하려면 고유한 클래스에 DependencyProperty 식별자가 필요합니다. get 접근자를 구현하는 GetValue 호출의 매개 변수로 DependencyProperty 사용합니다.

  • DependencyProperty 식별자는 메타데이터를 사용하는 다른 메서드가 표준 형식으로 액세스할 수 있도록 속성 시스템에 종속성 속성을 노출합니다. 예를 들어 일부 DependencyObjectGetLocalValueEnumerator 호출하고 로컬로 설정된 속성(값 및 식별자)의 열거형을 가져온 경우 읽기 전용 종속성 속성에 대해 반환된 식별자는 키가 아닌 DependencyProperty 값이 됩니다. DependencyProperty 식별자를 노출하지 않으면 어떤 방식으로든 읽기 전용 종속성 속성의 보안이 증가하지 않으며, 후속 파생 클래스 및 클래스 인스턴스 모두에 대해 속성을 포함하는 작업이 더 불편해집니다.

클래스에 DependencyProperty 식별자를 노출하려면 키에서 직접 DependencyProperty 호출합니다. 이 값을 사용하여 클래스에 DependencyPropertyKey병렬로 public static readonlyDependencyProperty 식별자를 만듭니다.

적용 대상

추가 정보