AttributeTableBuilder.AddCallback 方法

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

添加一个在需要指定类型的元数据时调用的回调。

命名空间:  Microsoft.Windows.Design.Metadata
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public Sub AddCallback ( _
    type As Type, _
    callback As AttributeCallback _
)
public void AddCallback(
    Type type,
    AttributeCallback callback
)
public:
void AddCallback(
    Type^ type, 
    AttributeCallback^ callback
)
member AddCallback : 
        type:Type * 
        callback:AttributeCallback -> unit 
public function AddCallback(
    type : Type, 
    callback : AttributeCallback
)

参数

  • type
    类型:System.Type
    要为其要添加元数据特性的类型。

备注

Callback 可以按需将元数据添加到特性表,这比在创建表时添加元数据更加有效。

创建大特性表时,通过 AttributeCallbackBuilder 类使用 AddCallback 方法。

示例

下面的代码示例演示如何使用 AddCallback 方法和 AttributeTableBuilder 类来创建和填充特性表。 此代码示例摘自为 AttributeCallbackBuilder 类提供的一个更大的示例。

// Container for any general design-time metadata to initialize.
// Designers look for a type in the design-time assembly that 
// implements IProvideAttributeTable. If found, designers instantiate 
// this class and access its AttributeTable property automatically.
internal class Metadata : IProvideAttributeTable
{
    // Accessed by the designer to register any design-time metadata.
    public AttributeTable AttributeTable
    {
        get
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();

            // Build the attribute table by using the AttributeCallbackBuilder 
            // class. The attribute table is not populated until the designer
            // needs it, which is more efficient for large attribute tables.
            builder.AddCallback(
                typeof(Button),
                delegate(AttributeCallbackBuilder callbackBuilder)
                {
                    callbackBuilder.AddCustomAttributes(
                        new DefaultPropertyAttribute("Content"));

                    // Apply the ReadOnlyAttribute to the Background property 
                    // of the Button class.
                    callbackBuilder.AddCustomAttributes(
                        "Background",
                        new ReadOnlyAttribute(true));
                });

            return builder.CreateTable();
        }
    }
}

.NET Framework 安全性

请参见

参考

AttributeTableBuilder 类

Microsoft.Windows.Design.Metadata 命名空间

AttributeTable

AttributeCallbackBuilder