BindableAttribute Classe

Definição

Especifica se um membro é normalmente usado para associação. Essa classe não pode ser herdada.

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
Herança
BindableAttribute
Atributos

Exemplos

O exemplo de código a seguir marca uma propriedade conforme apropriado para associar dados.

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

O próximo exemplo de código mostra como marcar o valor do BindableAttribute para MyProperty. Primeiro, o código obtém um PropertyDescriptorCollection com todas as propriedades do objeto . Em seguida, o código indexa no PropertyDescriptorCollection para obter MyProperty. Por fim, o código retorna os atributos dessa propriedade e os salva na variável de atributos. O exemplo de código apresenta duas maneiras diferentes de marcar o valor do BindableAttribute. No segundo fragmento de código, o exemplo chama o Equals método . No último fragmento de código, o exemplo usa a Bindable propriedade para marcar o valor.

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 você marcou uma classe com o BindableAttribute, use o exemplo de código a seguir para marcar o valor.

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

Comentários

Você pode especificar esse atributo para vários membros, normalmente propriedades, em um controle .

Se uma propriedade tiver sido marcada com o BindableAttribute definido como true, uma notificação de alteração de propriedade deverá ser gerada para essa propriedade. Isso significa que, se a Bindable propriedade for Yes, a associação de dados bidirecional terá suporte. Se Bindable for No, você ainda poderá associar à propriedade, mas ela não deverá ser mostrada no conjunto padrão de propriedades a serem associadas, pois ela pode ou não gerar uma notificação de alteração de propriedade.

Observação

Quando você marca uma propriedade com definido como BindableAttributetrue, o valor desse atributo é definido como o membro Yesconstante . Para uma propriedade marcada com o BindableAttribute definido como false, o valor é No. Portanto, para marcar o valor desse atributo em seu código, você deve especificar o atributo como BindableAttribute.Yes ou BindableAttribute.No.

Cuidado

Você só pode usar esse atributo em tempo de design. Nada impede que você vincule a qualquer propriedade durante o tempo de execução.

Para obter mais informações, consulte Atributos.

Construtores

BindableAttribute(BindableSupport)

Inicializa uma nova instância da classe BindableAttribute com um dos valores BindableSupport.

BindableAttribute(BindableSupport, BindingDirection)

Inicializa uma nova instância da classe BindableAttribute.

BindableAttribute(Boolean)

Inicializa uma nova instância da classe BindableAttribute com um valor booliano.

BindableAttribute(Boolean, BindingDirection)

Inicializa uma nova instância da classe BindableAttribute.

Campos

Default

Especifica o valor padrão para o BindableAttribute, que é No. Este campo é somente leitura.

No

Especifica que uma propriedade não é normalmente usada para associação. Este campo é somente leitura.

Yes

Especifica que uma propriedade é normalmente usada para associação. Este campo é somente leitura.

Propriedades

Bindable

Obtém um valor que indica que uma propriedade normalmente é usada para associação.

Direction

Obtém um valor que indica a direção da associação de dados desta propriedade.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Determina se dois objetos BindableAttribute são iguais.

GetHashCode()

Serve como uma função hash para a classe BindableAttribute.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Confira também