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.
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 首先,程式碼會取得包含所有物件屬性的 a 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,則支援雙向資料綁定。 如果 Bindable 是 No,你仍然可以綁定該屬性,但它不應該顯示在預設的綁定屬性集合中,因為可能會也可能不會觸發屬性變更通知。
備註
當你將屬性標記為 BindableAttributetrue時,該屬性的值會被設定為常數成員 Yes。 對於標記為 BindableAttribute 的 false屬性,值為 No。 因此,要檢查程式碼中該屬性的值,必須指定 BindableAttribute.Yes 為 或 BindableAttribute.No。
謹慎
這個屬性只能在設計時使用。 在執行期間,沒有任何東西能阻止你綁定任何屬性。
如需詳細資訊,請參閱屬性。
建構函式
| 名稱 | Description |
|---|---|
| BindableAttribute(BindableSupport, BindingDirection) |
初始化 BindableAttribute 類別的新執行個體。 |
| BindableAttribute(BindableSupport) |
初始化一個新的類別實例 BindableAttribute ,使用其中一個 BindableSupport 值。 |
| BindableAttribute(Boolean, BindingDirection) |
初始化 BindableAttribute 類別的新執行個體。 |
| BindableAttribute(Boolean) |
初始化一個帶有布林值的新 BindableAttribute 類別實例。 |
欄位
| 名稱 | Description |
|---|---|
| Default |
指定 的預設值 BindableAttribute,即 No。 此欄位是唯讀的。 |
| No |
規定某屬性通常不用於綁定。 此欄位是唯讀的。 |
| Yes |
規定通常使用某個屬性作為綁定。 此欄位是唯讀的。 |
屬性
| 名稱 | Description |
|---|---|
| Bindable |
會得到一個值,表示某屬性通常用於綁定。 |
| Direction |
會獲得一個值,指示該屬性資料綁定的方向。 |
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷兩個 BindableAttribute 物體是否相等。 |
| GetHashCode() |
作為類別的 BindableAttribute 雜湊函數。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
判斷此屬性是否為預設值。 |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _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) |