更新 : 2007 年 11 月
メタデータ ストアに渡すことができる属性テーブルを作成します。
名前空間 : Microsoft.Windows.Design.Metadata
アセンブリ : Microsoft.Windows.Design (Microsoft.Windows.Design.dll 内)
構文
'宣言
Public Class AttributeTableBuilder
'使用
Dim instance As AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
public class AttributeTableBuilder
解説
属性テーブルの作成は、まず 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
' 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 IRegisterMetadata
' Called by the designer to register any design-time metadata.
Public Sub Register() Implements IRegisterMetadata.Register
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 properties As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(GetType(Button))
Dim pd As PropertyDescriptor = properties("Foreground")
builder.AddCustomAttributes( _
GetType(Button), _
pd, _
New ReadOnlyAttribute(True))
builder.AddCustomAttributes( _
GetType(Button), _
Button.WidthProperty, _
New ReadOnlyAttribute(True))
Dim members As MemberInfo() = GetType(Button).GetMember("Height")
builder.AddCustomAttributes( _
GetType(Button), _
members(0), _
New ReadOnlyAttribute(True))
Dim attributes As AttributeTable = builder.CreateTable()
MetadataStore.AddAttributeTable(attributes)
End Sub
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;
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();
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));
PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(typeof(Button));
PropertyDescriptor pd = properties["Foreground"];
builder.AddCustomAttributes(
typeof(Button),
pd,
new ReadOnlyAttribute(true));
builder.AddCustomAttributes(
typeof(Button),
Button.WidthProperty,
new ReadOnlyAttribute(true));
MemberInfo[] members = typeof(Button).GetMember("Height");
builder.AddCustomAttributes(
typeof(Button),
members[0],
new ReadOnlyAttribute(true));
AttributeTable attributes = builder.CreateTable();
MetadataStore.AddAttributeTable(attributes);
}
}
}
継承階層
System.Object
Microsoft.Windows.Design.Metadata.AttributeTableBuilder
スレッド セーフ
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
参照
参照
Microsoft.Windows.Design.Metadata 名前空間