AttributeTable 클래스

업데이트: 2007년 11월

디자인 타임 모양 및 동작을 정의하는 메타데이터 특성 테이블입니다.

네임스페이스:  Microsoft.Windows.Design.Metadata
어셈블리:  Microsoft.Windows.Design(Microsoft.Windows.Design.dll)

구문

Public NotInheritable Class AttributeTable

Dim instance As AttributeTable
public sealed class AttributeTable
public ref class AttributeTable sealed
public final class AttributeTable

설명

AttributeTable 클래스를 사용하여 디자인 타임 메타데이터 특성을 WPF(Windows Presentation Foundation) 형식에 연결할 수 있습니다.

특성 테이블은 기본적으로 읽기 전용 사전이지만 키와 값이 개별적으로 계산됩니다. 특정 형식에 대한 특성이 들어 있는 경우 특성 테이블을 쿼리하는 것이 효율적입니다. 실제 특성 집합은 요청 시 만들어집니다.

특성 테이블을 만들려면 AttributeTableBuilder 클래스의 CreateTable 메서드를 호출합니다.

예제

다음 코드 예제에서는 특성 테이블을 만들고 값을 채우는 방법을 보여 줍니다. 자세한 내용은 연습: 디자인 타임 표시기 만들기를 참조하십시오.

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
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()

        ' 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()

        MetadataStore.AddAttributeTable(attributes)

        Dim hasCustomAttributes As Boolean = attributes.ContainsAttributes(GetType(Button))

        Dim types As IEnumerable(Of Type) = attributes.AttributedTypes

        ' The following code shows how to retrieve custom attributes
        ' using the GetCustomAttributes method overloads.

        Dim attrs0 As IEnumerable = attributes.GetCustomAttributes(GetType(Button))

        Dim attrs1 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), "Background")

        Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(Button))
        Dim pd As PropertyDescriptor = properties("Background")
        Dim attrs2 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), pd)

        Dim attrs3 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), Button.BackgroundProperty)

        Dim members As MemberInfo() = GetType(Button).GetMembers()
        Dim i As Integer
        For i = 0 To members.Length
            If members(i).Name = "Background" Then
                Dim attrs4 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), members(i))
            End If
        Next i

    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();

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

            AttributeTable attributes = builder.CreateTable();

            MetadataStore.AddAttributeTable(attributes);

            bool hasCustomAttributes = attributes.ContainsAttributes(typeof(Button));

            IEnumerable<Type> types = attributes.AttributedTypes;

            // The following code shows how to retrieve custom attributes
            // using the GetCustomAttributes method overloads.

            IEnumerable attrs0 = attributes.GetCustomAttributes(typeof(Button));

            IEnumerable attrs1 = attributes.GetCustomAttributes(
                typeof(Button), 
                "Background");

            PropertyDescriptorCollection properties = 
                TypeDescriptor.GetProperties(typeof(Button));
            PropertyDescriptor pd = properties["Background"];
            IEnumerable attrs2 = attributes.GetCustomAttributes(typeof(Button), pd);

            IEnumerable attrs3 = attributes.GetCustomAttributes(
                typeof(Button),
                Button.BackgroundProperty);

            MemberInfo[] members = typeof(Button).GetMembers();
            for (int i = 0; i < members.Length; i++)
            {
                if (members[i].Name == "Background")
                {
                    IEnumerable attrs4 = attributes.GetCustomAttributes(
                        typeof(Button), 
                        members[i]);
                }
            }
        }
    }
}

상속 계층 구조

System.Object
  Microsoft.Windows.Design.Metadata.AttributeTable

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

AttributeTable 멤버

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

AttributeTableBuilder

기타 리소스

메타데이터 저장소