DependencyProperty.RegisterAttached 메서드

정의

속성에 대해 지정된 속성 이름, 속성 형식, 소유자 유형 및 속성 메타데이터를 사용하여 연결된 종속성 속성을 등록합니다.

 static DependencyProperty RegisterAttached(winrt::hstring const& name, TypeName const& propertyType, TypeName const& ownerType, PropertyMetadata const& defaultMetadata);
public static DependencyProperty RegisterAttached(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata);
function registerAttached(name, propertyType, ownerType, defaultMetadata)
Public Shared Function RegisterAttached (name As String, propertyType As Type, ownerType As Type, defaultMetadata As PropertyMetadata) As DependencyProperty

매개 변수

name
String

winrt::hstring

등록할 종속성 속성의 이름입니다.

propertyType
TypeName Type

형식 참조로 속성의 형식입니다(Microsoft .NET용 System.Type , Visual C++ 구성 요소 확장용 TypeName 도우미 구조체(C++/CX)).

ownerType
TypeName Type

종속성 속성을 형식 참조로 등록하는 소유자 형식입니다(Microsoft .NET용 System.Type , Visual C++ 구성 요소 확장용 TypeName 도우미 구조체(C++/CX)).

defaultMetadata
PropertyMetadata

속성 메타데이터 instance. 여기에는 PropertyChangedCallback 구현 참조가 포함될 수 있습니다.

반환

클래스에서 공용 정적 읽기 전용 필드의 값을 설정하는 데 사용해야 하는 종속성 속성 식별자입니다. 그런 다음, 해당 식별자는 나중에 프로그래밍 방식으로 값을 설정하거나 Binding을 연결하는 등의 작업을 위해 연결된 속성을 참조하는 데 사용됩니다.

예제

이 예제에서는 DependencyObject에서 파생되는 클래스를 정의하고 식별자 필드와 함께 연결된 속성을 정의합니다. 이 클래스의 시나리오는 다른 UI 요소가 XAML에서 설정할 수 있는 연결된 속성을 선언하는 서비스 클래스이며, 서비스는 런타임에 해당 UI 요소의 연결된 속성 값에 대해 잠재적으로 작동합니다. 자세한 예제는 사용자 지정 연결된 속성을 참조하세요.

public abstract class AquariumServices : DependencyObject
{
    public enum Buoyancy {Floats,Sinks,Drifts}

    public static readonly DependencyProperty BuoyancyProperty = DependencyProperty.RegisterAttached(
      "Buoyancy",
      typeof(Buoyancy),
      typeof(AquariumServices),
      new PropertyMetadata(Buoyancy.Floats)
    );
    public static void SetBuoyancy(DependencyObject element, Buoyancy value)
    {
        element.SetValue(BuoyancyProperty, value);
    }
    public static Buoyancy GetBuoyancy(DependencyObject element)
    {
        return (Buoyancy)element.GetValue(BuoyancyProperty);
    }
}
Public Class AquariumServices
    Inherits DependencyObject
    Public Enum Buoyancy
        Floats
        Sinks
        Drifts
    End Enum

    Public Shared ReadOnly BuoyancyProperty As DependencyProperty = _
          DependencyProperty.RegisterAttached(
          "Buoyancy", _
          GetType(Buoyancy), _
          GetType(AquariumServices), _
          New PropertyMetadata(Buoyancy.Floats))


    Public Sub SetBuoyancy(element As DependencyObject, value As Buoyancy)
        element.SetValue(BuoyancyProperty, value)
    End Sub
    Public Function GetBuoyancy(element As DependencyObject) As Buoyancy
        GetBuoyancy = CType(element.GetValue(BuoyancyProperty), Buoyancy)
    End Function
End Class

적용 대상

추가 정보