다음을 통해 공유


방법: 메타데이터 저장소 사용

업데이트: 2007년 11월

확장성을 사용하여 Windows Presentation Foundation(WPF) Designer for Visual Studio를 사용자 지정할 때 사용자 지정 컨트롤을 만드는 경우가 많습니다. 컨트롤의 코드와 컨트롤의 디자인 타임 동작을 정의하는 메타데이터는 별도의 어셈블리에 구성됩니다. 메타데이터는 MetadataStore에 구성됩니다. 자세한 내용은 WPF Designer 확장성 아키텍처를 참조하십시오.

메타데이터 저장소에는 사용자 지정 표시기(Adorner), 사용자 지정 상황에 맞는 메뉴 및 사용자 지정 속성 편집기 등의 디자인 타임 동작에 대한 정보가 저장됩니다. 메타데이터 저장소는 코드 기반 특성 테이블로 구현됩니다.

참고:

메타데이터 어셈블리를 로드하면 먼저 *.Design.dll이 로드된 다음 *.VisualStudio.Design.dll 또는 *.Expression.Design.dll이 로드됩니다. 따라서 디자이너 고유의 메타데이터가 공통 공유 메타데이터를 재정의합니다.

메타데이터 저장소에 사용자 지정 특성 테이블 추가

사용자 지정 컨트롤을 로드할 때 디자이너에서는 IRegisterMetadata를 구현하는 형식을 해당 디자인 타임 어셈블리에서 찾습니다. 이 형식이 있으면 형식을 인스턴스화하고 형식의 Register 메타데이터를 자동으로 호출합니다.

메타데이터 저장소에 사용자 지정 특성 테이블을 추가하려면

  1. 컨트롤의 일반 디자인 타임 어셈블리(<Your Control>.Design.dll)에서 Metadata.cs 또는 Metadata.vb라는 파일을 추가합니다.

  2. 메타데이터 파일에서 IRegisterMetadata를 구현하는 클래스를 추가하고 Register 메서드를 구현합니다.

  3. AttributeTableBuilder 개체를 인스턴스화하고 AddCustomAttributes 메서드를 호출하여 개체에 특성을 추가합니다.

  4. AddAttributeTable 메서드를 호출하여 메타데이터 저장소에 AttributeTable을 추가합니다.

  5. Visual Studio의 디자인 타임 어셈블리(<Your Control>.VisualStudio.Design.dll)에 대해 1-4단계를 반복합니다.

예제

다음 예제에서는 사용자 지정 컨트롤에 대한 메타데이터를 추가합니다. 이 코드에서는 사용자 지정 속성 편집기를 사용자 지정 컨트롤의 속성에 연결합니다.

internal class Metadata : Microsoft.Windows.Design.Metadata.IRegisterMetadata
{
    public void Register()
    {
        Microsoft.Windows.Design.Metadata.AttributeTableBuilder builder = new Microsoft.Windows.Design.Metadata.AttributeTableBuilder();

        //Property Editor
        builder.AddCustomAttributes(typeof(<Your Custom Control>), <Property>, new System.ComponentModel.EditorAttribute(typeof(<Your Custom Editor>), typeof(<Your Custom Editor>)));

        //Category Editor
        builder.AddCustomAttributes(typeof(<Your Custom Control>), new System.ComponentModel.EditorAttribute(typeof(<Your Custom Editor>), typeof(<Your Custom Editor>)));

        Microsoft.Windows.Design.Metadata.MetadataStore.AddAttributeTable(builder.CreateTable());
    }
}
Friend Class Metadata
    Implements Microsoft.Windows.Design.Metadata.IRegisterMetadata

    Public Sub Register() Implements Microsoft.Windows.Design.Metadata.IRegisterMetadata.Register

        Dim builder As New Microsoft.Windows.Design.Metadata.AttributeTableBuilder()

        'Property Editor
        builder.AddCustomAttributes(GetType(<Your Custom Control>), <Property>, New System.ComponentModel.EditorAttribute(GetType(<Your Custom Editor>), GetType(<Your Custom Editor>)))

        'Category Editor
        builder.AddCustomAttributes(GetType(<Your Custom Control>), New System.ComponentModel.EditorAttribute(GetType(<Your Custom Editor>), GetType(<Your Custom Editor>)))

        Microsoft.Windows.Design.Metadata.MetadataStore.AddAttributeTable(builder.CreateTable())
    End Sub
End Class

다음 예제에서는 사용자 지정 컨트롤에 대한 메타데이터를 추가합니다. 이 코드에서는 사용자 지정 표시기와 사용자 지정 상황에 맞는 메뉴를 사용자 지정 컨트롤에 연결합니다.

internal class Metadata : Microsoft.Windows.Design.Metadata.IRegisterMetadata
{
    public void Register()
    {
        Microsoft.Windows.Design.Metadata.AttributeTableBuilder builder = new Microsoft.Windows.Design.Metadata.AttributeTableBuilder();

        //Adorners
        builder.AddCustomAttributes(typeof(<Your Custom Control>), new Microsoft.Windows.Design.Features.FeatureAttribute(typeof(<Your Custom Adorner Provider>)));
        builder.AddCustomAttributes(typeof(<Your Custom Control>), new Microsoft.Windows.Design.Features.FeatureAttribute(typeof(<Your Custom Adorner Provider>)));

        //MenuActions
        builder.AddCustomAttributes(typeof(<Your Custom Control>), new Microsoft.Windows.Design.Features.FeatureAttribute(typeof(<Your Custom Context Menu Provider>)));

        Microsoft.Windows.Design.Metadata.MetadataStore.AddAttributeTable(builder.CreateTable());
    }
}
Friend Class Metadata
    Implements Microsoft.Windows.Design.Metadata.IRegisterMetadata

    Public Sub Register() Implements Microsoft.Windows.Design.Metadata.IRegisterMetadata.Register

        Dim builder As New Microsoft.Windows.Design.Metadata.AttributeTableBuilder()

        'Adorners
        builder.AddCustomAttributes(GetType(<Your Custom Control>), New Microsoft.Windows.Design.Features.FeatureAttribute(GetType(<Your Custom Adorner Provider>)))
        builder.AddCustomAttributes(GetType(<Your Custom Control>), New Microsoft.Windows.Design.Features.FeatureAttribute(GetType(<Your Custom Adorner Provider>)))

        'MenuActions
        builder.AddCustomAttributes(GetType(<Your Custom Control>), New Microsoft.Windows.Design.Features.FeatureAttribute(GetType(<Your Custom Context Menu Provider>)))

        Microsoft.Windows.Design.Metadata.MetadataStore.AddAttributeTable(builder.CreateTable())
    End Sub
End Class

참고 항목

개념

메타데이터 저장소

참조

AdornerProvider

ContextMenuProvider

기타 리소스

기본 확장성 개념

WPF Designer 확장성 이해

WPF Designer 확장성