Sdílet prostřednictvím


BindableAttribute Třída

Definice

Určuje, jestli se člen obvykle používá pro vazbu. Tuto třídu nelze zdě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 podle potřeby k 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.
        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

Následující příklad kódu ukazuje, jak zkontrolovat hodnotu BindableAttribute pro MyProperty. Nejprve kód získá PropertyDescriptorCollection všechny vlastnosti objektu. Dále se kód indexuje do získání PropertyDescriptorCollectionMyProperty. 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. Ve druhém fragmentu kódu volá příklad metodu Equals . V posledním fragmentu kódu příklad používá 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í BindableAttributepříkazu , pomocí následujícího příkladu kódu zkontrolujte hodnotu.

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 vlastností ovládacího prvku.

Pokud byla vlastnost označena nastavenou BindableAttribute na truehodnotu , měla by být pro danou vlastnost vyvolána oznámení o změně vlastnosti. To znamená, že pokud Bindable je Yesvlastnost , je podporována obousměrná datová vazba. Pokud Bindable ano No, můžete stále vytvořit vazbu na vlastnost, ale neměl by být zobrazena ve výchozí sadě vlastností, které se mají svázat, protože může nebo nemusí vyvolat oznámení o změně vlastnosti.

Poznámka:

Když označíte vlastnost nastavenou BindableAttribute na truehodnotu , hodnota tohoto atributu je nastavena na konstantní člen Yes. Pro vlastnost označenou nastavenou BindableAttribute na falsehodnotu je Nohodnota . Proto chcete-li 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 vám nic nebrání v vazbě na libovolnou vlastnost.

Další informace naleznete v tématu Atributy.

Konstruktory

Name Description
BindableAttribute(BindableSupport, BindingDirection)

Inicializuje novou instanci BindableAttribute třídy.

BindableAttribute(BindableSupport)

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

BindableAttribute(Boolean, BindingDirection)

Inicializuje novou instanci BindableAttribute třídy.

BindableAttribute(Boolean)

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

Pole

Name Description
Default

Určuje výchozí hodnotu pro BindableAttributehodnotu , která je No. Toto pole je jen pro čtení.

No

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

Yes

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

Vlastnosti

Name Description
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 tento Attribute.

(Zděděno od Attribute)

Metody

Name Description
Equals(Object)

Určuje, zda jsou dva BindableAttribute objekty stejné.

GetHashCode()

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

GetType()

Získá Type aktuální instance.

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

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

Match(Object)

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

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

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

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

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

(Zděděno od Object)

Explicitní implementace rozhraní

Name Description
_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é