BindableAttribute 类

定义

指定 C++ 中定义的类型可用于绑定。

public ref class BindableAttribute sealed : Attribute
/// [Windows.Foundation.Metadata.AttributeUsage(System.AttributeTargets.RuntimeClass)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class BindableAttribute final : Attribute
/// [Windows.Foundation.Metadata.AttributeUsage(System.AttributeTargets.RuntimeClass)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.AttributeName("bindable")]
class BindableAttribute final : Attribute
[Windows.Foundation.Metadata.AttributeUsage(System.AttributeTargets.RuntimeClass)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class BindableAttribute : Attribute
[Windows.Foundation.Metadata.AttributeUsage(System.AttributeTargets.RuntimeClass)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.AttributeName("bindable")]
public sealed class BindableAttribute : Attribute
Public NotInheritable Class BindableAttribute
Inherits Attribute
继承
BindableAttribute
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

下面的代码示例演示此属性的典型使用模式。 有关完整的代码列表,请参阅 XAML 数据绑定示例

如果使用的是 C++/WinRT,则仅当使用 {Binding} 标记扩展时,才需要添加 BindableAttribute。 如果使用 {x:Bind} 标记扩展,则不需要 BindableAttribute (,有关详细信息,请参阅 XAML 控件;绑定到 C++/WinRT 属性) 。

// MyColors.idl
namespace MyColorsApp
{
    [bindable]
    [default_interface]
    runtimeclass MyColors : Windows.UI.Xaml.Data.INotifyPropertyChanged
    {
        MyColors();
        Windows.UI.Xaml.Media.SolidColorBrush Brush1;
    }
}
[Windows::UI::Xaml::Data::Bindable]
public ref class Employee sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
{
    // ...
}

注解

将此属性应用于基于 C++ 的数据类,使其能够用作绑定源。 公共语言运行时 (CLR) 类型(包括 C# 和 Microsoft Visual Basic 中定义的所有类型)默认可绑定。 还可以通过实现 ICustomPropertyProvider 使类型可绑定。 有关详细信息,请参阅深入了解数据绑定

构造函数

BindableAttribute()

初始化 BindableAttribute 类的新实例。

适用于

另请参阅