AttributeCallback, délégué
Appelé lorsque des attributs sont nécessaires pour un type.
Espace de noms : Microsoft.Windows.Design.Metadata
Assembly : Microsoft.Windows.Design.Extensibility (dans Microsoft.Windows.Design.Extensibility.dll)
Syntaxe
'Déclaration
Public Delegate Sub AttributeCallback ( _
builder As AttributeCallbackBuilder _
)
public delegate void AttributeCallback(
AttributeCallbackBuilder builder
)
public delegate void AttributeCallback(
AttributeCallbackBuilder^ builder
)
type AttributeCallback =
delegate of
builder:AttributeCallbackBuilder -> unit
JScript ne prend pas en charge les délégués.
Paramètres
- builder
Type : Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder
AttributeCallbackBuilder qui peut être utilisé pour ajouter des attributs.Les délégués AttributeCallbackBuilder ne peuvent générer des attributs que pour le type qui demande des métadonnées.
Notes
Utilisez le délégué AttributeCallback pour remplir une grande table d'attributs. En utilisant le modèle de rappel, le remplissage de la table d'attributs est différé jusqu'à ce que le concepteur ait besoin de métadonnées pour un type au moment du design.
Exemples
L'exemple de code suivant indique comment créer et remplir une table d'attributs à l'aide de 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;
// The ProvideMetadata assembly-level attribute indicates to designers
// that this assembly contains a class that provides an attribute table.
[assembly: ProvideMetadata(typeof(CustomControlLibrary.VisualStudio.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 IProvideAttributeTable. If found, designers instantiate
// this class and access its AttributeTable property automatically.
internal class Metadata : IProvideAttributeTable
{
// Accessed by the designer to register any design-time metadata.
public AttributeTable AttributeTable
{
get
{
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));
});
return builder.CreateTable();
}
}
}
}
Voir aussi
Référence
Microsoft.Windows.Design.Metadata, espace de noms
Autres ressources
Procédure pas à pas : création d'un ornement au moment du design