BindableAttribute クラス

定義

メンバーが通常、バインディングに使用されるかどうかを指定します。 このクラスは継承できません。

public ref class BindableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BindableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type BindableAttribute = class
    inherit Attribute
Public NotInheritable Class BindableAttribute
Inherits Attribute
継承
BindableAttribute
属性

次のコード例では、データのバインドに適した プロパティをマークします。

property int MyProperty 
{
   [System::ComponentModel::Bindable(true)]
   int get()
   {
      // Insert code here.
      return 0;
   }

   [System::ComponentModel::Bindable(true)]
   void set( int )
   {
      // Insert code here.
   }
}
[Bindable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
<Bindable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
         ' Insert code here.
    End Set
End Property

次のコード例では、 の 値をチェックする方法をBindableAttributeMyProperty示します。 最初に、コードは オブジェクトのすべてのプロパティを持つ を取得 PropertyDescriptorCollection します。 次に、コードが にインデックスを作成 PropertyDescriptorCollection して を取得 MyPropertyします。 最後に、このコードは、このプロパティの属性を返し、属性変数に保存します。 このコード例では、 の値をチェックする 2 つの異なる方法をBindableAttribute示します。 2 番目のコード フラグメントでは、 メソッドを呼び出します Equals 。 最後のコード フラグメントでは、 プロパティをBindable使用して値をチェックします。

using namespace System::ComponentModel;

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

// Checks to see if the value of the BindableAttribute is Yes.
if ( attributes[ BindableAttribute::typeid ]->Equals( BindableAttribute::Yes ) )
{
   // Insert code here.
}

// This is another way to see whether the property is bindable.
BindableAttribute^ myAttribute = static_cast<BindableAttribute^>(attributes[ BindableAttribute::typeid ]);
if ( myAttribute->Bindable )
{
   // Insert code here.
}

// Yet another way to see whether the property is bindable.
if ( attributes->Contains( BindableAttribute::Yes ) )
{
   // Insert code here.
}
   // Gets the attributes for the property.
    AttributeCollection attributes =
       TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

    // Checks to see if the value of the BindableAttribute is Yes.
    if(attributes[typeof(BindableAttribute)].Equals(BindableAttribute.Yes)) {
       // Insert code here.
    }

    // This is another way to see whether the property is bindable.
    BindableAttribute myAttribute =
       (BindableAttribute)attributes[typeof(BindableAttribute)];
    if(myAttribute.Bindable) {
       // Insert code here.
    }

// Yet another way to see whether the property is bindable.
if (attributes.Contains(BindableAttribute.Yes)) {
   // Insert code here.
}
    ' Gets the attributes for the property.
    Dim attributes As AttributeCollection = _
        TypeDescriptor.GetProperties(Me)("MyProperty").Attributes
    
    ' Checks to see if the value of the BindableAttribute is Yes.
    If attributes(GetType(BindableAttribute)).Equals(BindableAttribute.Yes) Then
        ' Insert code here.
    End If 
    
    ' This is another way to see whether the property is bindable.
    Dim myAttribute As BindableAttribute = _
        CType(attributes(GetType(BindableAttribute)), BindableAttribute)
    If myAttribute.Bindable Then
        ' Insert code here.
    End If 

' Yet another way to see whether the property is bindable.
If attributes.Contains(BindableAttribute.Yes) Then
' Insert code here.
End If

でクラスをマークした場合はBindableAttribute、次のコード例を使用して値をチェックします。

using namespace System::ComponentModel;
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ BindableAttribute::typeid ]->Equals( BindableAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes =
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(BindableAttribute)].Equals(BindableAttribute.Yes)) {
    // Insert code here.
 }
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(BindableAttribute)).Equals(BindableAttribute.Yes) Then
    ' Insert code here.
End If

注釈

この属性は、コントロール上の複数のメンバー (通常はプロパティ) に指定できます。

プロパティが にtrue設定された状態でBindableAttributeマークされている場合は、そのプロパティに対してプロパティ変更通知を発生させる必要があります。 つまり、 プロパティが の Bindable 場合は Yes、双方向データ バインディングがサポートされます。 が Noの場合Bindable、プロパティにバインドすることはできますが、プロパティ変更通知を発生させる場合と発生しない場合があるため、バインドするプロパティの既定のセットには表示しないでください。

Note

を にtrue設定して プロパティBindableAttributeをマークすると、この属性の値は定数メンバー Yesに設定されます。 が にfalse設定されたプロパティのBindableAttribute場合、値は ですNo。 したがって、コードでこの属性の値をチェックするには、 属性を または BindableAttribute.NoとしてBindableAttribute.Yes指定する必要があります。

注意事項

この属性は、デザイン時にのみ使用できます。 実行時にプロパティにバインドすることを妨げるものは何もありません。

詳細については、「属性」を参照してください。

コンストラクター

BindableAttribute(BindableSupport)

BindableAttribute クラスの新しいインスタンスを BindableSupport の値のいずれかで初期化します。

BindableAttribute(BindableSupport, BindingDirection)

BindableAttribute クラスの新しいインスタンスを初期化します。

BindableAttribute(Boolean)

Boolean 値を指定して、BindableAttribute クラスの新しいインスタンスを初期化します。

BindableAttribute(Boolean, BindingDirection)

BindableAttribute クラスの新しいインスタンスを初期化します。

フィールド

Default

BindableAttribute の既定値 (No) を指定します。 このフィールドは読み取り専用です。

No

プロパティが通常はバインドに使用されないことを指定します。 このフィールドは読み取り専用です。

Yes

プロパティが通常、バインドに使用されることを指定します。 このフィールドは読み取り専用です。

プロパティ

Bindable

プロパティが通常、バインドに使用されることを示す値を取得します。

Direction

このプロパティのデータ バインディングの方向を示す値を取得します。

TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)

メソッド

Equals(Object)

2 つの BindableAttribute オブジェクトが等しいかどうかを判断します。

GetHashCode()

BindableAttribute クラスのハッシュ関数として機能します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

この属性が既定値かどうかを判断します。

Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください