Compartilhar via


Classe AttributeTableBuilder

Cria um tabela de atributos que podem ser passados para o armazenamento de metadados.

Namespace:  Microsoft.Windows.Design.Metadata
Assembly:  Microsoft.Windows.Design (em Microsoft.Windows.Design.dll)

Sintaxe

Public Class AttributeTableBuilder

Dim instance As AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
public class AttributeTableBuilder

Comentários

Para criar um tabela de atributos, você inicia com a criação de uma instância da classe AttributeTableBuilder.Você adiciona metadados ao construtor de tabela de atributos chamando as sobrecargas AddCustomAttributes.Quando você terminar de adicionar os metadados, você produz um tabela de atributos a partir de construtor de tabela de atributos chamando o método CreateTable.Os métodos do construtor de tabela de atributos dão suporte a representantes de retorno de chamada, portanto, a criação da tabela de atributos pode ser adiada até que seja necessária.

Use o AttributeCallbackBuilder classe em vez da AttributeTableBuilder Se você estiver adicionando muitos atributos de classe. Essa abordagem adia a criação de atributos até que os metadados de designer solicitações para o tipo de destino.

Exemplos

O exemplo de código a seguir mostra como usar o AttributeTableBuilder classe para criar e popular um atributo tabela. Para obter mais informações, consulte Demonstra Passo a passo: Criando um Adorner de tempo de design.

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

Hierarquia de herança

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

Acesso thread-safe

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Membros AttributeTableBuilder

Namespace Microsoft.Windows.Design.Metadata

AttributeTable

AttributeCallbackBuilder

Outros recursos

Armazenamento de metadados