AttributeTableBuilder.AddCallback 方法
更新:2007 年 11 月
添加一个在需要指定类型的元数据时调用的回调。
命名空间: Microsoft.Windows.Design.Metadata
程序集: Microsoft.Windows.Design(在 Microsoft.Windows.Design.dll 中)
语法
声明
Public Sub AddCallback ( _
type As Type, _
callback As AttributeCallback _
)
用法
Dim instance As AttributeTableBuilder
Dim type As Type
Dim callback As AttributeCallback
instance.AddCallback(type, callback)
public void AddCallback(
Type type,
AttributeCallback callback
)
public:
void AddCallback(
Type^ type,
AttributeCallback^ callback
)
public function AddCallback(
type : Type,
callback : AttributeCallback
)
参数
type
类型:System.Type要向其添加元数据属性的类型。
callback
类型:Microsoft.Windows.Design.Metadata.AttributeCallback向 Type 添加元数据的 AttributeCallback。
备注
Callback 可在需要时向属性表中添加元数据,这比在创建表时添加元数据更为高效。
在生成较大的属性表时,请将 AddCallback 方法用于 AttributeCallbackBuilder 类。
示例
下面的代码示例演示如何使用 AddCallback 方法和 AttributeTableBuilder 类创建和填充属性表。此代码示例摘自为 AttributeCallbackBuilder 类提供的一个更大的示例。
// Container for any general design-time metadata to initialize.
// Designers look for a type in the design-time assembly that
// implements IRegisterMetadata. If found, designers instantiate
// this class and call its Register() method automatically.
internal class Metadata : IRegisterMetadata
{
// Called by the designer to register any design-time metadata.
public void Register()
{
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));
PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(typeof(Button));
PropertyDescriptor pd = properties["Foreground"];
callbackBuilder.AddCustomAttributes(
pd,
new ReadOnlyAttribute(true));
callbackBuilder.AddCustomAttributes(
Button.WidthProperty,
new TypeConverterAttribute(typeof(LengthConverter)),
new DescriptionAttribute("This is the width"));
MemberInfo[] members = typeof(Button).GetMember("Height");
callbackBuilder.AddCustomAttributes(
members[0],
new ReadOnlyAttribute(true));
});
MetadataStore.AddAttributeTable(builder.CreateTable());
}
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.Windows.Design.Metadata 命名空间