Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Actualización: noviembre 2007
Una instancia de esta clase se pasa a los delegados de devolución de llamada para rellenar lentamente los atributos para un tipo.
Espacio de nombres: Microsoft.Windows.Design.Metadata
Ensamblado: Microsoft.Windows.Design (en Microsoft.Windows.Design.dll)
Sintaxis
Public NotInheritable Class AttributeCallbackBuilder
Dim instance As AttributeCallbackBuilder
public sealed class AttributeCallbackBuilder
public ref class AttributeCallbackBuilder sealed
public final class AttributeCallbackBuilder
Comentarios
Utilice el método AttributeCallbackBuilder para rellenar un objeto AttributeTable a petición. Esto es especialmente importante para las tablas de atributos que contienen muchos atributos. Si está especificando sólo unos cuantos atributos para un tipo, use únicamente AttributeTableBuilder.
Con el formato de delegado, no se construye ningún atributo hasta que el diseñador solicita los metadatos para el tipo de destino. AttributeTableBuilder transfiere esta información de devolución de llamada a AttributeTable y la conserva. Por consiguiente, estos delegados de devolución de llamada sólo se invocan a petición. Una vez invocados, AttributeTable almacena sus resultados en memoria caché.
Habilite la creación de atributos a petición con el método AddCallback.
Ejemplos
En el siguiente ejemplo de código se muestra cómo crear y rellenar una tabla de atributos mediante la clase AttributeCallbackBuilder.
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());
}
}
}
Jerarquía de herencia
System.Object
Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder
Seguridad para subprocesos
Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Vea también
Referencia
AttributeCallbackBuilder (Miembros)
Microsoft.Windows.Design.Metadata (Espacio de nombres)