BindableAttribute BindableAttribute BindableAttribute BindableAttribute Class

定義

指定成員是否通常使用於繫結。Specifies whether a member is typically used for binding. 這個類別無法被繼承。This class cannot be inherited.

public ref class BindableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BindableAttribute : Attribute
type BindableAttribute = class
    inherit Attribute
Public NotInheritable Class BindableAttribute
Inherits Attribute
繼承
BindableAttributeBindableAttributeBindableAttributeBindableAttribute
屬性

範例

下列程式碼範例會適當地標示屬性,以將資料系結至。The following code example marks a property as appropriate to bind data to.

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代碼範例顯示如何檢查的值。The next code example shows how to check the value of the BindableAttribute for MyProperty. 首先,程式碼會取得PropertyDescriptorCollection具有物件之所有屬性的。First, the code gets a PropertyDescriptorCollection with all the properties for the object. 接下來,程式碼會編制PropertyDescriptorCollection索引, MyProperty以取得。Next, the code indexes into the PropertyDescriptorCollection to get MyProperty. 最後,程式碼會傳回這個屬性的屬性,並將它們儲存在 attributes 變數中。Finally, the code returns the attributes for this property and saves them in the attributes variable. 此程式碼範例會提供兩種不同的方式來檢查BindableAttribute的值。The code example presents two different ways to check the value of the BindableAttribute. 在第二個程式碼片段中,此範例Equals會呼叫方法。In the second code fragment, the example calls the Equals method. 在最後一個程式碼片段中,此範例會Bindable使用屬性來檢查值。In the last code fragment, the example uses the Bindable property to check the value.

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,請使用下列程式碼範例來檢查值。If you marked a class with the BindableAttribute, use the following code example to check the value.

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 

備註

您可以針對控制項上的多個成員(通常是屬性)指定此屬性。You can specify this attribute for multiple members, typically properties, on a control.

如果已BindableAttribute true將屬性(property)標示為,則應該針對該屬性引發屬性變更通知。If a property has been marked with the BindableAttribute set to true, then a property change notification should be raised for that property. 這表示如果Bindable屬性為Yes,則支援雙向資料系結。This means that if the Bindable property is Yes, then two-way data binding is supported. 如果BindableNo,您仍然可以系結至屬性,但它不應該顯示在要系結的預設屬性集中,因為它不一定會引發屬性變更通知。If Bindable is No, you can still bind to the property, but it should not be shown in the default set of properties to bind to, because it might or might not raise a property change notification.

注意

當您將BindableAttribute設定為的屬性標記true為時,這個屬性的值會設定為常數成員YesWhen you mark a property with BindableAttribute set to true, the value of this attribute is set to the constant member Yes. 對於以設定為BindableAttribute false的標記的屬性,此值No為。For a property marked with the BindableAttribute set to false, the value is No. 因此,若要在您的程式碼中檢查這個屬性的值,您必須將BindableAttribute.Yes屬性BindableAttribute.No指定為或。Therefore, to check the value of this attribute in your code, you must specify the attribute as BindableAttribute.Yes or BindableAttribute.No.

警告

您只能在設計階段使用這個屬性。You can use this attribute at design time only. 任何內容都不會讓您在執行時間系結至任何屬性。Nothing prevents you from binding to any property during run time.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

BindableAttribute(BindableSupport) BindableAttribute(BindableSupport) BindableAttribute(BindableSupport) BindableAttribute(BindableSupport)

使用其中一個 BindableSupport值,初始化 BindableAttribute 類別的新執行個體。Initializes a new instance of the BindableAttribute class with one of the BindableSupport values.

BindableAttribute(BindableSupport, BindingDirection) BindableAttribute(BindableSupport, BindingDirection) BindableAttribute(BindableSupport, BindingDirection) BindableAttribute(BindableSupport, BindingDirection)

初始化 BindableAttribute 類別的新執行個體。Initializes a new instance of the BindableAttribute class.

BindableAttribute(Boolean) BindableAttribute(Boolean) BindableAttribute(Boolean) BindableAttribute(Boolean)

使用布林值 (Boolean),初始化 BindableAttribute 類別的新執行個體。Initializes a new instance of the BindableAttribute class with a Boolean value.

BindableAttribute(Boolean, BindingDirection) BindableAttribute(Boolean, BindingDirection) BindableAttribute(Boolean, BindingDirection) BindableAttribute(Boolean, BindingDirection)

初始化 BindableAttribute 類別的新執行個體。Initializes a new instance of the BindableAttribute class.

欄位

Default Default Default Default

指定 BindableAttribute 的預設值,就是 NoSpecifies the default value for the BindableAttribute, which is No. 此欄位為唯讀。This field is read-only.

No No No No

指定屬性通常不用於繫結。Specifies that a property is not typically used for binding. 此欄位為唯讀。This field is read-only.

Yes Yes Yes Yes

指定屬性通常用於繫結。Specifies that a property is typically used for binding. 此欄位為唯讀。This field is read-only.

屬性

Bindable Bindable Bindable Bindable

取得值,指出屬性通常用於繫結。Gets a value indicating that a property is typically used for binding.

Direction Direction Direction Direction

取得值,指出這個屬性的資料繫結方向。Gets a value indicating the direction or directions of this property's data binding.

TypeId TypeId TypeId TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷兩個 BindableAttribute 物件是否相等。Determines whether two BindableAttribute objects are equal.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為 BindableAttribute 類別的雜湊函式。Serves as a hash function for the BindableAttribute class.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

判斷這個屬性是否為預設值。Determines if this attribute is the default.

Match(Object) Match(Object) Match(Object) Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用於

另請參閱