BindableAttribute Klasa

Definicja

Określa, czy element członkowski jest zwykle używany do wiązania. Klasa ta nie może być dziedziczona.

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
Dziedziczenie
BindableAttribute
Atrybuty

Przykłady

Poniższy przykład kodu oznacza właściwość odpowiednio do powiązania danych.

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

W następnym przykładzie kodu pokazano, jak sprawdzić wartość elementu BindableAttribute dla MyPropertyelementu . Najpierw kod pobiera PropertyDescriptorCollection obiekt ze wszystkimi właściwościami obiektu. Następnie kod indeksuje element , PropertyDescriptorCollection aby pobrać element MyProperty. Na koniec kod zwraca atrybuty tej właściwości i zapisuje je w zmiennej atrybutów. W przykładzie kodu przedstawiono dwa różne sposoby sprawdzania wartości .BindableAttribute W drugim fragmentze kodu przykład wywołuje metodę Equals . W ostatnim fragmentze kodu przykład używa Bindable właściwości , aby sprawdzić wartość.

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

Jeśli oznaczono klasę za BindableAttributepomocą klasy , użyj poniższego przykładu kodu, aby sprawdzić wartość.

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

Uwagi

Ten atrybut można określić dla wielu elementów członkowskich, zazwyczaj właściwości, w kontrolce.

Jeśli właściwość została oznaczona z ustawioną BindableAttribute wartością true, należy zgłosić powiadomienie o zmianie właściwości dla tej właściwości. Oznacza to, że jeśli Bindable właściwość ma Yeswartość , obsługiwane jest dwukierunkowe powiązanie danych. Jeśli Bindable parametr ma Nowartość , nadal można powiązać z właściwością, ale nie powinien być wyświetlany w domyślnym zestawie właściwości do powiązania, ponieważ może lub nie może zgłosić powiadomienia o zmianie właściwości.

Uwaga

Gdy oznaczysz właściwość BindableAttribute z ustawioną wartością true, wartość tego atrybutu jest ustawiona na stały element członkowski Yes. W przypadku właściwości oznaczonej wartością ustawioną BindableAttribute na false, wartość to No. W związku z tym, aby sprawdzić wartość tego atrybutu w kodzie, należy określić atrybut jako BindableAttribute.Yes lub BindableAttribute.No.

Przestroga

Tego atrybutu można używać tylko w czasie projektowania. Nic nie uniemożliwia wiązania z dowolną właściwością w czasie wykonywania.

Aby uzyskać więcej informacji, zobacz Atrybuty.

Konstruktory

BindableAttribute(BindableSupport)

Inicjuje BindableAttribute nowe wystąpienie klasy przy użyciu jednej z BindableSupport wartości.

BindableAttribute(BindableSupport, BindingDirection)

Inicjuje nowe wystąpienie klasy BindableAttribute.

BindableAttribute(Boolean)

Inicjuje BindableAttribute nowe wystąpienie klasy z wartością logiczną.

BindableAttribute(Boolean, BindingDirection)

Inicjuje nowe wystąpienie klasy BindableAttribute.

Pola

Default

Określa wartość domyślną BindableAttributeelementu , czyli No. To pole jest tylko do odczytu.

No

Określa, że właściwość nie jest zwykle używana do powiązania. To pole jest tylko do odczytu.

Yes

Określa, że właściwość jest zwykle używana do wiązania. To pole jest tylko do odczytu.

Właściwości

Bindable

Pobiera wartość wskazującą, że właściwość jest zwykle używana do tworzenia powiązań.

Direction

Pobiera wartość wskazującą kierunek lub kierunki powiązania danych tej właściwości.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

Określa, czy dwa BindableAttribute obiekty są równe.

GetHashCode()

Służy jako funkcja skrótu BindableAttribute dla klasy .

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Określa, czy ten atrybut jest domyślny.

Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

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

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też