更新 : 2007 年 11 月
このクラスのインスタンスは、型の属性を後で設定するコールバック デリゲートに渡されます。
名前空間 : Microsoft.Windows.Design.Metadata
アセンブリ : Microsoft.Windows.Design (Microsoft.Windows.Design.dll 内)
構文
'宣言
Public NotInheritable Class AttributeCallbackBuilder
'使用
Dim instance As AttributeCallbackBuilder
public sealed class AttributeCallbackBuilder
public ref class AttributeCallbackBuilder sealed
public final class AttributeCallbackBuilder
解説
AttributeCallbackBuilder を使用すると、AttributeTable の作成が要求時に行われるようになります。これは、多数の属性を保持する属性テーブルで特に重要です。1 つの型に数個の属性しか指定しない場合は、AttributeTableBuilder を使用します。
デリゲート形式を使用した場合、ターゲット型のメタデータがデザイナによって要求されるまで、属性は作成されません。AttributeTableBuilder は、このコールバック情報を AttributeTable に転送して保持します。このため、これらのコールバック デリゲートは要求された場合にのみ呼び出されます。呼び出されると、その結果は AttributeTable によってキャッシュされます。
要求に応じた属性の作成を有効にするには、AddCallback メソッドを使用します。
例
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;
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 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());
}
}
}
継承階層
System.Object
Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder
スレッド セーフ
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
参照
参照
Microsoft.Windows.Design.Metadata 名前空間