BindableAttribute Kelas

Definisi

Menentukan apakah anggota biasanya digunakan untuk pengikatan. Kelas ini tidak dapat diwariskan.

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
Warisan
BindableAttribute
Atribut

Contoh

Contoh kode berikut menandai properti yang sesuai untuk mengikat data.

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

Contoh kode berikutnya menunjukkan cara memeriksa nilai BindableAttribute untuk MyProperty. Pertama, kode mendapatkan PropertyDescriptorCollection dengan semua properti untuk objek . Selanjutnya, kode mengindeks ke PropertyDescriptorCollection dalam untuk mendapatkan MyProperty. Akhirnya, kode mengembalikan atribut untuk properti ini dan menyimpannya dalam variabel atribut. Contoh kode menyajikan dua cara berbeda untuk memeriksa nilai BindableAttribute. Dalam fragmen kode kedua, contoh memanggil Equals metode . Dalam fragmen kode terakhir, contoh menggunakan Bindable properti untuk memeriksa nilai.

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

Jika Anda menandai kelas dengan BindableAttribute, gunakan contoh kode berikut untuk memeriksa nilainya.

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

Keterangan

Anda dapat menentukan atribut ini untuk beberapa anggota, biasanya properti, pada kontrol.

Jika properti telah ditandai dengan diatur ke true, maka pemberitahuan perubahan properti harus dinaikkan untuk properti tersebutBindableAttribute. Ini berarti bahwa jika Bindable properti adalah Yes, maka pengikatan data dua arah didukung. Jika Bindable adalah No, Anda masih dapat mengikat ke properti , tetapi tidak boleh ditampilkan dalam kumpulan properti default untuk diikat, karena mungkin atau mungkin tidak menaikkan pemberitahuan perubahan properti.

Catatan

Saat Anda menandai properti dengan BindableAttribute diatur ke true, nilai atribut ini diatur ke anggota Yeskonstanta . Untuk properti yang ditandai dengan BindableAttribute diatur ke false, nilainya adalah No. Oleh karena itu, untuk memeriksa nilai atribut ini dalam kode Anda, Anda harus menentukan atribut sebagai BindableAttribute.Yes atau BindableAttribute.No.

Perhatian

Anda hanya dapat menggunakan atribut ini pada waktu desain. Tidak ada yang mencegah Anda mengikat ke properti apa pun selama durasi.

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

BindableAttribute(BindableSupport)

Menginisialisasi instans BindableAttribute baru kelas dengan salah BindableSupport satu nilai.

BindableAttribute(BindableSupport, BindingDirection)

Menginisialisasi instans baru kelas BindableAttribute.

BindableAttribute(Boolean)

Menginisialisasi instans BindableAttribute baru kelas dengan nilai Boolean.

BindableAttribute(Boolean, BindingDirection)

Menginisialisasi instans baru kelas BindableAttribute.

Bidang

Default

Menentukan nilai default untuk BindableAttribute, yaitu No. Bidang ini hanya-baca.

No

Menentukan bahwa properti biasanya tidak digunakan untuk pengikatan. Bidang ini hanya-baca.

Yes

Menentukan bahwa properti biasanya digunakan untuk pengikatan. Bidang ini hanya-baca.

Properti

Bindable

Mendapatkan nilai yang menunjukkan bahwa properti biasanya digunakan untuk pengikatan.

Direction

Mendapatkan nilai yang menunjukkan arah atau arah pengikatan data properti ini.

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)

Metode

Equals(Object)

Menentukan apakah dua BindableAttribute objek sama.

GetHashCode()

Berfungsi sebagai fungsi hash untuk BindableAttribute kelas .

GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Menentukan apakah atribut ini adalah default.

Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

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

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga