BindableAttribute Classe

Definição

Especifica se um elemento é tipicamente usado para ligação. Esta 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 seguinte marca uma propriedade como apropriada para atribuir 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.
        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 verificar o valor do BindableAttribute para MyProperty. Primeiro, o código recebe a PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, o código indexa-se para obter PropertyDescriptorCollectionMyProperty. Finalmente, o código devolve os atributos desta propriedade e guarda-os na variável de atributos. O exemplo de código apresenta duas formas diferentes de verificar 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 verificar 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 marcou uma classe com o BindableAttribute, use o seguinte exemplo de código para verificar 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

Observações

Pode especificar este atributo para múltiplos membros, normalmente propriedades, num controlo.

Se uma propriedade tiver sido marcada com o BindableAttribute conjunto para true, então deve ser lançada uma notificação de alteração de propriedade para essa propriedade. Isto significa que, se a Bindable propriedade for Yes, então a ligação de dados bidirecional é suportada. Se Bindable for No, ainda pode vincular à propriedade, mas não deve aparecer no conjunto padrão de propriedades a atribuir, porque pode ou não gerar uma notificação de alteração de propriedade.

Note

Quando se marca uma propriedade com BindableAttribute definido como true, o valor deste atributo é definido como o elemento Yesconstante . Para uma propriedade marcada com o BindableAttribute conjunto de , falseo valor é No. Portanto, para verificar o valor deste atributo no seu código, deve especificar o atributo como BindableAttribute.Yes ou BindableAttribute.No.

Atenção

Podes usar este atributo apenas no momento do design. Nada impede que associes a qualquer propriedade durante a execução.

Para obter mais informações, consulte Atributos.

Construtores

Name Description
BindableAttribute(BindableSupport, BindingDirection)

Inicializa uma nova instância da BindableAttribute classe.

BindableAttribute(BindableSupport)

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

BindableAttribute(Boolean, BindingDirection)

Inicializa uma nova instância da BindableAttribute classe.

BindableAttribute(Boolean)

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

Campos

Name Description
Default

Especifica o valor padrão para o BindableAttribute, que é No. Este campo é só de leitura.

No

Especifica que uma propriedade não é normalmente usada para ligação. Este campo é só de leitura.

Yes

Especifica que uma propriedade é normalmente usada para ligação. Este campo é só de leitura.

Propriedades

Name Description
Bindable

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

Direction

Obtém um valor que indica a direção ou direções da ligação de dados desta propriedade.

TypeId

Quando implementado numa classe derivada, obtém um identificador único para esta Attribute.

(Herdado de Attribute)

Métodos

Name Description
Equals(Object)

Determina se dois BindableAttribute objetos são iguais.

GetHashCode()

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

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

Match(Object)

Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Devolve uma cadeia que representa o objeto atual.

(Herdado de Object)

Implementações de Interface Explícita

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho.

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

Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

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

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

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

(Herdado de Attribute)

Aplica-se a

Ver também