次の方法で共有


BindableAttribute クラス

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

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)

構文

'宣言
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class BindableAttribute
    Inherits Attribute
'使用
Dim instance As BindableAttribute
[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class BindableAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] 
public ref class BindableAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class BindableAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class BindableAttribute extends Attribute

解説

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

プロパティが値 trueBindableAttribute でマークされている場合は、そのプロパティに関するプロパティ変更通知が発生します。つまり、Bindable プロパティが Yes の場合は、双方向のデータ バインディングがサポートされることになります。BindableNo の場合も、そのプロパティにバインドすることはできますが、プロパティ変更通知が発生する場合としない場合とがあるため、そのプロパティはバインドできる既定のプロパティ セットの 1 つとしては表示されません。

注意

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

ヒント

この属性は、デザイン時にだけ使用できます。実行時は任意のプロパティに自由にバインドできます。

詳細については、属性の概要属性を使用したメタデータの拡張 の各トピックを参照してください。

使用例

プロパティがデータのバインド先として適切であることをマークするコード例を次に示します。

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

   [System::ComponentModel::Bindable(true)]
   void set( int )
   {
      // Insert code here.
   }
}
/** @attribute Bindable(true)
 */
/** @property 
 */
public int get_MyProperty()
{
    // Insert code here.
    return 0;
} //get_MyProperty()

/** @property 
 */
public void set_MyProperty(int value)
{
    // Insert code here.
} //set_MyProperty

MyPropertyBindableAttribute の値を確認する方法を次のコード例に示します。最初に、オブジェクトのすべてのプロパティを保持する PropertyDescriptorCollection を取得します。次に、PropertyDescriptorCollection にインデックスを付けて、MyProperty を取得します。最後に、このプロパティの属性を返し、それらの属性を属性変数に保存します。このコード例は、BindableAttribute の値を確認する 2 種類の方法を示しています。2 番目のコード片では、Equals メソッドを呼び出します。最後のコード片では、Bindable プロパティを使用して値を確認します。

    ' 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
   // 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.
}
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)
    .get_Item("MyProperty").get_Attributes();

// Checks to see if the value of the BindableAttribute is Yes.
if (attributes.get_Item(BindableAttribute.class.ToType())
    .Equals(BindableAttribute.Yes)) {
    // Insert code here.
}

// This is another way to see whether the property is bindable.
BindableAttribute myAttribute = (BindableAttribute)
    (attributes.get_Item(BindableAttribute.class.ToType()));
if (myAttribute.get_Bindable()) {
    // Insert code here.
}

// Yet another way to see whether the property is bindable.
if (attributes.Contains(BindableAttribute.Yes)) {
    // Insert code here.
}

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

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

継承階層

System.Object
   System.Attribute
    System.ComponentModel.BindableAttribute

スレッド セーフ

この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

BindableAttribute メンバ
System.ComponentModel 名前空間
Attribute
PropertyDescriptor
AttributeCollection クラス
PropertyDescriptorCollection