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

型参照としてのプロパティの型。

ownerType
TypeName Type

依存関係プロパティを型参照として登録している所有者型。

defaultMetadata
PropertyMetadata

プロパティ メタデータ インスタンス。 これには 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);
    }
}

適用対象

こちらもご覧ください