Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Aggiornamento: novembre 2007
Un'istanza di questa classe viene passata ai delegati di callback per popolare lentamente gli attributi per un tipo.
Spazio dei nomi: Microsoft.Windows.Design.Metadata
Assembly: Microsoft.Windows.Design (in Microsoft.Windows.Design.dll)
Sintassi
Public NotInheritable Class AttributeCallbackBuilder
Dim instance As AttributeCallbackBuilder
public sealed class AttributeCallbackBuilder
public ref class AttributeCallbackBuilder sealed
public final class AttributeCallbackBuilder
Note
Utilizzare AttributeCallbackBuilder per popolare AttributeTable su richiesta. Questa funzione è particolarmente importante per le tabelle di attributi che contengono molti attributi. Se si specificano solo alcuni attributi per un tipo, utilizzare AttributeTableBuilder da solo.
Utilizzando il formato di delegato, non vengono costruiti attributi finché la finestra di progettazione non richiede metadati per il tipo di destinazione. AttributeTableBuilder trasferisce queste informazioni di callback in AttributeTable e le conserva. Pertanto, questi delegati di callback vengono richiamati solo su richiesta. Una volta richiamati, i relativi risultati vengono memorizzati nella cache da AttributeTable.
Attivare la creazione di attributi su richiesta utilizzando il metodo AddCallback.
Esempi
Nell'esempio di codice seguente viene illustrato come creare e popolare una tabella di attributi utilizzando la classe 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());
}
}
}
Gerarchia di ereditarietà
System.Object
Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder
Codice thread safe
Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.
Vedere anche
Riferimenti
Membri AttributeCallbackBuilder
Spazio dei nomi Microsoft.Windows.Design.Metadata
Altre risorse
Procedura dettagliata: creazione di uno strumento decorativo visuale in fase di progettazione