次の方法で共有


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 では、必要に応じてメタデータを属性テーブルに追加できます。この方法は、テーブルの作成時にメタデータを追加する方法より効率的です。

大きい属性テーブルを作成する場合は、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 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());
    }
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

AttributeTableBuilder クラス

AttributeTableBuilder メンバ

Microsoft.Windows.Design.Metadata 名前空間

AttributeTable

AttributeCallbackBuilder

その他の技術情報

メタデータ ストア