BindableAttribute Třída

Definice

Určuje, zda se člen obvykle používá pro vazbu. Tato třída se nemůže dědit.

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
Dědičnost
BindableAttribute
Atributy

Příklady

Následující příklad kódu označuje vlastnost, která je vhodná pro vytvoření vazby dat.

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

Další příklad kódu ukazuje, jak zkontrolovat hodnotu BindableAttribute pro MyProperty. Nejprve kód získá se PropertyDescriptorCollection všemi vlastnostmi objektu. Dále se kód indexuje do objektu , PropertyDescriptorCollection aby získal MyProperty. Nakonec kód vrátí atributy pro tuto vlastnost a uloží je do proměnné atributů. Příklad kódu představuje dva různé způsoby kontroly hodnoty BindableAttribute. V druhém fragmentu kódu volá příklad metodu Equals . V posledním fragmentu kódu používá příklad Bindable vlastnost ke kontrole hodnoty.

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

Pokud jste označili třídu pomocí BindableAttribute, zkontrolujte hodnotu pomocí následujícího příkladu kódu.

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

Poznámky

Tento atribut můžete zadat pro více členů, obvykle vlastnosti, v ovládacím prvku.

Pokud byla vlastnost označena nastavenou BindableAttribute na truehodnotu , mělo by se pro danou vlastnost vytvořit oznámení o změně vlastnosti. To znamená, že pokud Bindable je Yesvlastnost , podporuje se obousměrná datová vazba. Pokud Bindable je No, můžete i tak vytvořit vazbu k vlastnosti, ale nemělo by se zobrazovat ve výchozí sadě vlastností, se kterou chcete vytvořit vazbu, protože může nebo nemusí vyvolat oznámení o změně vlastnosti.

Poznámka

Když označíte vlastnost nastavenou BindableAttribute na true, hodnota tohoto atributu se nastaví na konstantní člen Yes. Pro vlastnost označenou nastavenou BindableAttribute na falsehodnotu je Nohodnota . Proto pokud chcete zkontrolovat hodnotu tohoto atributu v kódu, musíte zadat atribut jako BindableAttribute.Yes nebo BindableAttribute.No.

Upozornění

Tento atribut můžete použít pouze v době návrhu. Během běhu nic nebrání ve vazbě na libovolnou vlastnost.

Další informace najdete v tématu Atributy.

Konstruktory

BindableAttribute(BindableSupport)

Inicializuje novou instanci BindableAttribute třídy s jednou z BindableSupport hodnot.

BindableAttribute(BindableSupport, BindingDirection)

Inicializuje novou instanci BindableAttribute třídy.

BindableAttribute(Boolean)

Inicializuje novou instanci BindableAttribute třídy s logickou hodnotou.

BindableAttribute(Boolean, BindingDirection)

Inicializuje novou instanci BindableAttribute třídy.

Pole

Default

Určuje výchozí hodnotu pro BindableAttribute, což je No. Toto pole je jen ke čtení.

No

Určuje, že vlastnost se obvykle nepoužívá pro vazbu. Toto pole je jen ke čtení.

Yes

Určuje, že vlastnost se obvykle používá pro vazbu. Toto pole je jen ke čtení.

Vlastnosti

Bindable

Získá hodnotu označující, že vlastnost se obvykle používá pro vazbu.

Direction

Získá hodnotu označující směr nebo směry datové vazby této vlastnosti.

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tuto Attributetřídu .

(Zděděno od Attribute)

Metody

Equals(Object)

Určuje, zda jsou dva BindableAttribute objekty rovny.

GetHashCode()

Slouží jako hashovací funkce pro BindableAttribute třídu.

GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
IsDefaultAttribute()

Určuje, jestli je tento atribut výchozí.

Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, které lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také