次の方法で共有


AttributeTableBuilder クラス

デザイン時メタデータを定義する属性テーブルを作成します。

継承階層

System.Object
  Microsoft.Windows.Design.Metadata.AttributeTableBuilder

名前空間:  Microsoft.Windows.Design.Metadata
アセンブリ:  Microsoft.Windows.Design.Extensibility (Microsoft.Windows.Design.Extensibility.dll 内)

構文

'宣言
Public Class AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
type AttributeTableBuilder =  class end
public class AttributeTableBuilder

AttributeTableBuilder 型で公開されるメンバーは以下のとおりです。

コンストラクター

  名前 説明
パブリック メソッド AttributeTableBuilder AttributeTableBuilder クラスの新しいインスタンスを初期化します。

このページのトップへ

メソッド

  名前 説明
パブリック メソッド AddCallback 指定した型のメタデータが必要になったときに呼び出されるコールバックを追加します。
パブリック メソッド AddCustomAttributes(Assembly, array<Attribute[]) 提供された属性配列の内容をテーブル ビルダーに追加します。
パブリック メソッド AddCustomAttributes(Type, array<Attribute[]) テーブル ビルダーに提供された属性の内容を追加します。
パブリック メソッド AddCustomAttributes(Type, String, array<Attribute[]) 指定した名前のメンバーに属性を追加します。
パブリック メソッド AddTable 指定した属性テーブルの内容をテーブル ビルダーに追加します。
パブリック メソッド CreateTable AddCustomAttributes の呼び出しを通じて提供される、すべての属性定義が含まれる属性テーブルを作成します。
パブリック メソッド Equals 指定した Object が、現在の Object と等しいかどうかを判断します。 (Object から継承されます。)
プロテクト メソッド Finalize オブジェクトがガベージ コレクションにより収集される前に、そのオブジェクトがリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。)
パブリック メソッド GetHashCode 特定の型のハッシュ関数として機能します。 (Object から継承されます。)
パブリック メソッド GetType 現在のインスタンスの Type を取得します。 (Object から継承されます。)
プロテクト メソッド MemberwiseClone 現在の Object の簡易コピーを作成します。 (Object から継承されます。)
パブリック メソッド ToString 現在のオブジェクトを表す文字列を返します。 (Object から継承されます。)
パブリック メソッド ValidateTable このメソッドは、作成中の属性テーブルに有効な属性情報が含まれているかどうかを検証する目的で使用されます。

このページのトップへ

解説

属性テーブルの作成は、まず AttributeTableBuilder クラスのインスタンスを作成することから始まります。 AddCustomAttributes オーバーロードを呼び出すことにより、属性テーブル ビルダーにメタデータを追加します。 メタデータを追加し終わったら、CreateTable メソッドを呼び出して、属性テーブル ビルダーから属性テーブルを生成します。 属性テーブル ビルダーのメソッドはコールバック デリゲートをサポートしているため、属性テーブルの作成を必要になるまで延期できます。

多数の属性を追加する場合は、AttributeTableBuilder クラスではなく、AttributeCallbackBuilder クラスを使用します。 この方法では、デザイナーがターゲット型のメタデータを要求するまで属性の作成を延期できます。

AttributeTableBuilder クラスを使用して、属性テーブルを作成および設定する方法を次のコード例に示します。 詳細については、「チュートリアル : デザイン時装飾の作成」を参照してください。

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Reflection
Imports System.Text
Imports System.Windows.Media
Imports System.Windows.Controls
Imports System.Windows

Imports Microsoft.Windows.Design.Features
Imports 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(GetType(CustomControlLibrary.VisualStudio.Design.Metadata))> 

' 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.
Friend Class Metadata
    Implements IProvideAttributeTable

    ' Accessed by the designer to register any design-time metadata.
    Public ReadOnly Property AttributeTable() As AttributeTable _
        Implements IProvideAttributeTable.AttributeTable
        Get
            Dim builder As New AttributeTableBuilder()

            builder.AddCustomAttributes( _
                GetType(Button), _
                New DefaultPropertyAttribute("Content"))

            ' Apply the ReadOnlyAttribute to the Background property 
            ' of the Button class.
            builder.AddCustomAttributes( _
                GetType(Button), _
                "Background", _
                New ReadOnlyAttribute(True))

            Dim attributes As AttributeTable = builder.CreateTable()

            Return attributes
        End Get
    End Property

End Class
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
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();

                builder.AddCustomAttributes(
                    typeof(Button),
                    new DefaultPropertyAttribute("Content"));

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

                AttributeTable attributes = builder.CreateTable();

                return attributes;
            }
        }
    }
}

スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバーは、スレッド セーフです。 インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

参照

参照

Microsoft.Windows.Design.Metadata 名前空間

AttributeTable

AttributeCallbackBuilder