Condividi tramite


BindableAttribute Classe

Definizione

Specifica se un membro viene in genere utilizzato per l'associazione. Questa 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à
BindableAttribute
Attributi

Esempio

Nell'esempio di codice seguente viene contrassegnata 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.
        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, nell'esempio viene utilizzata 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, per tale proprietà deve essere generata una notifica di modifica della 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 o non generare una notifica di modifica della proprietà.

Annotazioni

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 l'associazione a qualsiasi proprietà durante l'esecuzione.

Per altre informazioni, vedere Attributi.

Costruttori

Nome Descrizione
BindableAttribute(BindableSupport, BindingDirection)

Inizializza una nuova istanza della classe BindableAttribute.

BindableAttribute(BindableSupport)

Inizializza una nuova istanza della BindableAttribute classe con uno dei BindableSupport valori .

BindableAttribute(Boolean, BindingDirection)

Inizializza una nuova istanza della classe BindableAttribute.

BindableAttribute(Boolean)

Inizializza una nuova istanza della BindableAttribute classe con un valore booleano.

Campi

Nome Descrizione
Default

Specifica il valore predefinito per , BindableAttributeovvero No. Il campo è di sola lettura.

No

Specifica che una proprietà non viene in genere utilizzata per l'associazione. Il campo è di sola lettura.

Yes

Specifica che una proprietà viene in genere utilizzata per l'associazione. Il campo è di sola lettura.

Proprietà

Nome Descrizione
Bindable

Ottiene un valore che indica che una proprietà viene in genere utilizzata per l'associazione.

Direction

Ottiene un valore che indica la direzione o le direzioni del data binding di questa proprietà.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Determina se due BindableAttribute oggetti sono uguali.

GetHashCode()

Funge da funzione hash per la BindableAttribute classe .

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Determina se questo attributo è l'impostazione predefinita.

Match(Object)

Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

Nome Descrizione
_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 per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per 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 alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da Attribute)

Si applica a

Vedi anche