BindableAttribute Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica se un membro viene generalmente utilizzato per l'associazione. La classe non può essere ereditata.
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
- Ereditarietà
- Attributi
Esempio
L'esempio di codice seguente contrassegna una proprietà come appropriato per associare i dati.
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
Nell'esempio di codice seguente viene illustrato come controllare il valore di BindableAttribute per MyProperty. Innanzitutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, il codice indicizza in PropertyDescriptorCollection per ottenere MyProperty. Infine, il codice restituisce gli attributi per questa proprietà e li salva nella variabile degli attributi. L'esempio di codice presenta due modi diversi per controllare il valore di BindableAttribute. Nel secondo frammento di codice l'esempio chiama il Equals metodo . Nell'ultimo frammento di codice l'esempio usa la Bindable proprietà per controllare il valore.
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
Se è stata contrassegnata una classe con BindableAttribute, usare l'esempio di codice seguente per controllare il valore.
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
Commenti
È possibile specificare questo attributo per più membri, in genere proprietà, in un controllo .
Se una proprietà è stata contrassegnata con l'oggetto BindableAttribute impostato su true, deve essere generata una notifica di modifica della proprietà per tale proprietà. Ciò significa che se la Bindable proprietà è Yes, il data binding bidirezionale è supportato. Se Bindable è No, è comunque possibile eseguire l'associazione alla proprietà, ma non deve essere visualizzata nel set predefinito di proprietà a cui eseguire l'associazione, perché potrebbe generare o meno una notifica di modifica della proprietà.
Nota
Quando si contrassegna una proprietà con BindableAttribute impostato su true, il valore di questo attributo viene impostato sul membro Yescostante . Per una proprietà contrassegnata con l'oggetto BindableAttribute impostato su false, il valore è No. Pertanto, per controllare il valore di questo attributo nel codice, è necessario specificare l'attributo come BindableAttribute.Yes o BindableAttribute.No.
Attenzione
È possibile usare questo attributo solo in fase di progettazione. Nulla impedisce di eseguire il binding a qualsiasi proprietà durante l'esecuzione.
Per altre informazioni, vedere Attributi.
Costruttori
| BindableAttribute(BindableSupport) |
Inizializza una nuova istanza della classe BindableAttribute con uno dei valori BindableSupport. |
| BindableAttribute(BindableSupport, BindingDirection) |
Inizializza una nuova istanza della classe BindableAttribute. |
| BindableAttribute(Boolean) |
Inizializza una nuova istanza della classe BindableAttribute con un valore booleano. |
| BindableAttribute(Boolean, BindingDirection) |
Inizializza una nuova istanza della classe BindableAttribute. |
Campi
| Default |
Consente di specificare il valore predefinito per l'attributo BindableAttribute, che è No. Questo campo è di sola lettura. |
| No |
Consente di specificare che una proprietà non viene generalmente utilizzata per l'associazione. Questo campo è di sola lettura. |
| Yes |
Consente di specificare che una proprietà viene generalmente utilizzata per l'associazione. Questo campo è di sola lettura. |
Proprietà
| Bindable |
Ottiene un valore che indica che una proprietà viene generalmente utilizzata per l'associazione. |
| Direction |
Ottiene un valore che indica la o le direzioni dell'associazione dati di questa proprietà. |
| TypeId |
Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute. (Ereditato da Attribute) |
Metodi
| Equals(Object) |
Determina se due oggetti BindableAttribute sono uguali. |
| GetHashCode() |
Viene utilizzato come funzione hash per la classe BindableAttribute. |
| GetType() |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
| IsDefaultAttribute() |
Determina se questo attributo è predefinito. |
| Match(Object) |
Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato. (Ereditato da Attribute) |
| MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch. (Ereditato da Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia. (Ereditato da Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornisce l'accesso a proprietà e metodi esposti da un oggetto. (Ereditato da Attribute) |