AttributeTableBuilder.AddCallback, méthode

Ajoute un rappel qui est appelé lorsque les métadonnées pour le type spécifié sont nécessaires.

Espace de noms :  Microsoft.Windows.Design.Metadata
Assembly :  Microsoft.Windows.Design.Extensibility (dans Microsoft.Windows.Design.Extensibility.dll)

Syntaxe

'Déclaration
Public Sub AddCallback ( _
    type As Type, _
    callback As AttributeCallback _
)
public void AddCallback(
    Type type,
    AttributeCallback callback
)
public:
void AddCallback(
    Type^ type, 
    AttributeCallback^ callback
)
member AddCallback : 
        type:Type * 
        callback:AttributeCallback -> unit 
public function AddCallback(
    type : Type, 
    callback : AttributeCallback
)

Paramètres

  • type
    Type : System.Type
    Type auquel ajouter des attributs de métadonnées.

Notes

Callback peut ajouter les métadonnées à la table d'attributs à la demande, ce qui est plus efficace qu'ajouter les métadonnées lors de la création de la table.

Utilisez la méthode AddCallback avec la classe AttributeCallbackBuilder lorsque vous générez une grande table d'attributs.

Exemples

L'exemple de code suivant indique comment créer et remplir une table d'attributs à l'aide de la méthode AddCallback et de la classe AttributeTableBuilder. Cet exemple de code fait partie d'un exemple plus complet fourni pour la classe AttributeCallbackBuilder.

// 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();
        }
    }
}

Sécurité .NET Framework

Voir aussi

Référence

AttributeTableBuilder Classe

Microsoft.Windows.Design.Metadata, espace de noms

AttributeTable

AttributeCallbackBuilder