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

下一個程式代碼範例示範如何檢查 BindableAttribute 的值 MyProperty。 首先,程式代碼會取得 PropertyDescriptorCollection 具有物件之所有屬性的 。 接下來,程式代碼會索引到 PropertyDescriptorCollection ,以取得 MyProperty。 最後,程式代碼會傳回此屬性的屬性,並將其儲存在屬性變數中。 程式代碼範例提供兩種不同的方法來檢查的值 BindableAttribute。 在第二個代碼段中,此範例會呼叫 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

備註

您可以為控制件上的多個成員指定這個屬性,通常是屬性。

如果屬性已標示BindableAttributetrue為 ,則應該針對該屬性引發屬性變更通知。 這表示如果 Bindable 屬性為 Yes,則支援雙向數據系結。 如果 BindableNo,您仍然可以系結至 屬性,但不應該顯示在要系結至的默認屬性集中,因為它可能會或可能不會引發屬性變更通知。

注意

當您將 屬性 BindableAttribute 標示為 true時,這個屬性的值會設定為常數成員 Yes。 對於標示為 的屬性,BindableAttributefalse此值為 No。 因此,若要檢查程式代碼中這個屬性的值,您必須將 屬性指定為 BindableAttribute.YesBindableAttribute.No

警告

您只能在設計時間使用此屬性。 [無] 可防止您在運行時間期間系結至任何屬性。

如需詳細資訊,請參閱屬性

建構函式

BindableAttribute(BindableSupport)

使用其中一個 BindableSupport值,初始化 BindableAttribute 類別的新執行個體。

BindableAttribute(BindableSupport, BindingDirection)

初始化 BindableAttribute 類別的新執行個體。

BindableAttribute(Boolean)

使用布林值 (Boolean),初始化 BindableAttribute 類別的新執行個體。

BindableAttribute(Boolean, BindingDirection)

初始化 BindableAttribute 類別的新執行個體。

欄位

Default

指定 BindableAttribute 的預設值,就是 No。 此欄位為唯讀。

No

指定屬性通常不用於繫結。 此欄位為唯讀。

Yes

指定屬性通常用於繫結。 此欄位為唯讀。

屬性

Bindable

取得值,指出屬性通常用於繫結。

Direction

取得值,指出這個屬性的資料繫結方向。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

判斷兩個 BindableAttribute 物件是否相等。

GetHashCode()

做為 BindableAttribute 類別的雜湊函式。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱