Compartilhar via


Classe AttributeCallbackBuilder

Uma instância dessa classe é passada para retorno de chamada delegados para popular os atributos de um tipo ociosamente.

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

Sintaxe

Public NotInheritable Class AttributeCallbackBuilder

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

Comentários

Use o AttributeCallbackBuilder para popular um AttributeTable sob demanda. Isso é especialmente importante para tabelas de atributos que mantêm muitos atributos.Se você especificar somente alguns atributos para um tipo, use o AttributeTableBuilder por si só.

Usando o formato de delegado, sem atributos são construídos até que os metadados para o tipo de destino é solicitado pelo designer.The AttributeTableBuilder transfere essas informações de retorno de chamada para o AttributeTable e preserva-lo. Portanto, esses delegados de retorno de chamada são invocados somente sob demanda.Uma vez chamado, seus resultados são armazenadas em cache pelo AttributeTable.

Habilitar criação sob demanda atributo usando o AddCallback método.

Exemplos

O exemplo de código a seguir mostra como criar e popular uma tabela de atributo usando o AttributeCallbackBuilder classe.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Reflection;
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();

            // Build the attribute table by using the AttributeCallbackBuilder 
            // class. The attribute table is not populated until the designer
            // needs it, which is more efficient for large attribute tables.
            builder.AddCallback(
                typeof(Button), 
                delegate(AttributeCallbackBuilder callbackBuilder)
            {
                callbackBuilder.AddCustomAttributes(
                    new DefaultPropertyAttribute("Content"));

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

                PropertyDescriptorCollection properties =
                    TypeDescriptor.GetProperties(typeof(Button));
                PropertyDescriptor pd = properties["Foreground"];
                callbackBuilder.AddCustomAttributes(
                    pd,
                    new ReadOnlyAttribute(true));

                callbackBuilder.AddCustomAttributes(
                   Button.WidthProperty,
                   new TypeConverterAttribute(typeof(LengthConverter)),
                   new DescriptionAttribute("This is the width"));

                MemberInfo[] members = typeof(Button).GetMember("Height");
                callbackBuilder.AddCustomAttributes(
                    members[0],
                    new ReadOnlyAttribute(true));
            });

            MetadataStore.AddAttributeTable(builder.CreateTable());
        }
    }
}

Hierarquia de herança

System.Object
  Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder

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 AttributeCallbackBuilder

Namespace Microsoft.Windows.Design.Metadata

AttributeTableBuilder

AddCallback

AttributeTable

Outros recursos

Armazenamento de metadados

Demonstra Passo a passo: Criando um Adorner de tempo de design