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 Attribute
Public 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。
注意
只能在设计时使用此属性。 在运行时,不会阻止绑定到任何属性。
有关更多信息,请参阅特性。
Bindable |
使用其中一个 BindableSupport 值初始化 BindableAttribute 类的新实例。 |
Bindable |
初始化 BindableAttribute 类的新实例。 |
Bindable |
用布尔值初始化 BindableAttribute 类的新实例。 |
Bindable |
初始化 BindableAttribute 类的新实例。 |
Default |
指定 BindableAttribute 的默认值,即 No。 此字段为只读。 |
No |
指定属性通常不用于绑定。 此字段为只读。 |
Yes |
指定属性通常用于绑定。 此字段为只读。 |
Bindable |
获取指示某个属性通常用于绑定的值。 |
Direction |
获取指示此属性的数据绑定方向的值。 |
Type |
在派生类中实现时,获取此 Attribute 的唯一标识符。 (继承自 Attribute) |
Equals(Object) |
确定两个 BindableAttribute 对象是否相等。 |
Get |
用作 BindableAttribute 类的哈希函数。 |
Get |
获取当前实例的 Type。 (继承自 Object) |
Is |
确定此特性是否为默认特性。 |
Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。 (继承自 Attribute) |
Memberwise |
创建当前 Object 的浅表副本。 (继承自 Object) |
To |
返回表示当前对象的字符串。 (继承自 Object) |
_Attribute. |
将一组名称映射为对应的一组调度标识符。 (继承自 Attribute) |
_Attribute. |
检索对象的类型信息,然后可以使用该信息获取接口的类型信息。 (继承自 Attribute) |
_Attribute. |
检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute) |
_Attribute. |
提供对某一对象公开的属性和方法的访问。 (继承自 Attribute) |
产品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |