AttributeCallback 委托

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

当某个类型需要特性时调用。

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

语法

声明
Public Delegate Sub AttributeCallback ( _
    builder As AttributeCallbackBuilder _
)
public delegate void AttributeCallback(
    AttributeCallbackBuilder builder
)
public delegate void AttributeCallback(
    AttributeCallbackBuilder^ builder
)
type AttributeCallback = 
    delegate of 
        builder:AttributeCallbackBuilder -> unit
JScript 不支持委托。

参数

备注

填充大特性表时,使用 AttributeCallback 委托。 通过使用回调模式,可以延迟填充特性表,直到设计人员需要某个类型的设计时元数据。

示例

下面的代码示例演示如何使用 AttributeCallbackBuilder 类创建和填充特性表。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;

using Microsoft.Windows.Design.Features;
using Microsoft.Windows.Design.Metadata;

// The ProvideMetadata assembly-level attribute indicates to designers
// that this assembly contains a class that provides an attribute table. 
[assembly: ProvideMetadata(typeof(CustomControlLibrary.VisualStudio.Design.Metadata))]

namespace CustomControlLibrary.VisualStudio.Design
{
    // 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();
            }
        }
    }
}

请参见

参考

Microsoft.Windows.Design.Metadata 命名空间

AttributeTableBuilder

AddCallback

AttributeTable

其他资源

演练:创建设计时装饰器

了解 WPF 设计器扩展性