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
Se llama cuando se necesitan atributos para un tipo.
Espacio de nombres: Microsoft.Windows.Design.Metadata
Ensamblado: Microsoft.Windows.Design (en Microsoft.Windows.Design.dll)
Sintaxis
Public Delegate Sub AttributeCallback ( _
builder As AttributeCallbackBuilder _
)
Dim instance As New AttributeCallback(AddressOf HandlerMethod)
public delegate void AttributeCallback(
AttributeCallbackBuilder builder
)
public delegate void AttributeCallback(
AttributeCallbackBuilder^ builder
)
JScript no admite delegados.
Parámetros
builder
Tipo: Microsoft.Windows.Design.Metadata.AttributeCallbackBuilderAttributeCallbackBuilder que se puede utilizar para agregar atributos. Los delegados AttributeCallbackBuilder sólo pueden construir atributos para el tipo que solicita los metadatos.
Comentarios
Utilice el delegado AttributeCallback cuando esté rellenando una tabla de atributos grande. Si usa el modelo de devolución de llamada, el relleno de la tabla de atributos se aplaza hasta que el diseñador necesite los metadatos en tiempo de diseño para un tipo.
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());
}
}
}
Vea también
Referencia
Microsoft.Windows.Design.Metadata (Espacio de nombres)