BindableAttribute Clase

Definición

Especifica si un miembro se usa normalmente para el enlace. Esta clase no puede heredarse.

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
Herencia
BindableAttribute
Atributos

Ejemplos

En el ejemplo de código siguiente se marca una propiedad según corresponda para enlazar datos.

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

En el ejemplo de código siguiente se muestra cómo comprobar el valor de para BindableAttributeMyProperty. En primer lugar, el código obtiene con PropertyDescriptorCollection todas las propiedades del objeto . A continuación, el código indexa en para PropertyDescriptorCollection obtener MyProperty. Por último, el código devuelve los atributos de esta propiedad y los guarda en la variable attributes. En el ejemplo de código se presentan dos maneras diferentes de comprobar el valor de BindableAttribute. En el segundo fragmento de código, el ejemplo llama al Equals método . En el último fragmento de código, en el ejemplo se usa la Bindable propiedad para comprobar el 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

Si marcó una clase con BindableAttribute, use el ejemplo de código siguiente para comprobar el 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

Comentarios

Puede especificar este atributo para varios miembros, normalmente propiedades, en un control .

Si una propiedad se ha marcado con el BindableAttribute establecido trueen , se debe generar una notificación de cambio de propiedad para esa propiedad. Esto significa que si la Bindable propiedad es Yes, se admite el enlace de datos bidireccional. Si Bindable es No, todavía puede enlazar a la propiedad , pero no debe mostrarse en el conjunto predeterminado de propiedades a las que enlazar, ya que podría o no generar una notificación de cambio de propiedad.

Nota:

Cuando se marca una propiedad con BindableAttribute establecida en true, el valor de este atributo se establece en el miembro Yesconstante . Para una propiedad marcada con el BindableAttribute valor establecido falseen , el valor es No. Por lo tanto, para comprobar el valor de este atributo en el código, debe especificar el atributo como BindableAttribute.Yes o BindableAttribute.No.

Precaución

Puede usar este atributo solo en tiempo de diseño. Nada impide que se enlace a ninguna propiedad durante el tiempo de ejecución.

Para obtener más información, consulte Attributes (Atributos).

Constructores

BindableAttribute(BindableSupport)

Inicializa una nueva instancia de la clase BindableAttribute con uno de los valores de BindableSupport.

BindableAttribute(BindableSupport, BindingDirection)

Inicializa una nueva instancia de la clase BindableAttribute.

BindableAttribute(Boolean)

Inicializa una nueva instancia de la clase BindableAttribute con un valor booleano.

BindableAttribute(Boolean, BindingDirection)

Inicializa una nueva instancia de la clase BindableAttribute.

Campos

Default

Especifica el valor predeterminado de BindableAttribute, que es No. Este campo es de solo lectura.

No

Especifica que una propiedad no se utiliza normalmente para el enlace. Este campo es de solo lectura.

Yes

Especifica que una propiedad se utiliza normalmente para el enlace. Este campo es de solo lectura.

Propiedades

Bindable

Obtiene un valor que indica que una propiedad se utiliza normalmente para el enlace.

Direction

Obtiene un valor que indica la dirección o direcciones del enlace de datos de esta propiedad.

TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.

(Heredado de Attribute)

Métodos

Equals(Object)

Determina si los dos objetos BindableAttribute son iguales.

GetHashCode()

Sirve como función hash para la clase BindableAttribute.

GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
IsDefaultAttribute()

Determina si este atributo es el valor predeterminado.

Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.

(Heredado de Attribute)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.

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

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.

(Heredado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).

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

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.

(Heredado de Attribute)

Se aplica a

Consulte también