BindableAttribute 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定成员是否通常用于绑定。 此类不能被继承。
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 AttributePublic NotInheritable Class BindableAttribute
Inherits Attribute- 继承
- 属性
示例
下面的代码示例将属性标记为适合将数据绑定到。
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。 最后,代码返回此属性的属性,并将其保存在 attributes 变量中。 代码示例提供了两种不同的方法来检查 的值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,则支持双向数据绑定。 如果 Bindable 为 No,则仍可以绑定到 属性,但它不应显示在要绑定到的默认属性集中,因为它可能会引发或可能不会引发属性更改通知。
注意
将 属性BindableAttributetrue标记为 时,此属性的值设置为常量成员 Yes。 对于标记为 BindableAttribute 设置为 false的属性,值为 No。 因此,若要在代码中检查此属性的值,必须将 特性指定为 BindableAttribute.Yes 或 BindableAttribute.No。
注意
只能在设计时使用此属性。 在运行时,不会阻止绑定到任何属性。
有关更多信息,请参阅特性。
构造函数
| BindableAttribute(BindableSupport) | 使用其中一个 BindableSupport 值初始化 BindableAttribute 类的新实例。 | 
| BindableAttribute(BindableSupport, BindingDirection) | 初始化 BindableAttribute 类的新实例。 | 
| BindableAttribute(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) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |