다음을 통해 공유


AttributeTableBuilder 클래스

업데이트: 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) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

AttributeTableBuilder 멤버

Microsoft.Windows.Design.Metadata 네임스페이스

AttributeTable

AttributeCallbackBuilder

기타 리소스

메타데이터 저장소