Condividi tramite


Classe AttributeTableBuilder

Crea una tabella di attributi che definisce metadati in fase di progettazione.

Gerarchia di ereditarietà

System.Object
  Microsoft.Windows.Design.Metadata.AttributeTableBuilder

Spazio dei nomi:  Microsoft.Windows.Design.Metadata
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)

Sintassi

'Dichiarazione
Public Class AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
type AttributeTableBuilder =  class end
public class AttributeTableBuilder

Il tipo AttributeTableBuilder espone i seguenti membri.

Costruttori

  Nome Descrizione
Metodo pubblico AttributeTableBuilder Inizializza una nuova istanza della classe AttributeTableBuilder.

In alto

Metodi

  Nome Descrizione
Metodo pubblico AddCallback Aggiunge un callback che viene richiamato sono necessari i metadati per il tipo specificato.
Metodo pubblico AddCustomAttributes(Assembly, array<Attribute[]) Aggiunge il contenuto della matrice di attributi specificata al generatore di tabelle.
Metodo pubblico AddCustomAttributes(Type, array<Attribute[]) Aggiunge il contenuto degli attributi specificati al generatore di tabelle.
Metodo pubblico AddCustomAttributes(Type, String, array<Attribute[]) Aggiunge attributi al membro con il nome specificato.
Metodo pubblico AddTable Aggiunge il contenuto della tabella di attributi specificata al generatore di tabelle.
Metodo pubblico CreateTable Crea una tabella di attributi che contiene tutte le definizioni di attributi fornite tramite chiamate a AddCustomAttributes.
Metodo pubblico Equals Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente. (Ereditato da Object)
Metodo protetto Finalize Consente a un oggetto di provare a liberare risorse ed eseguire altre operazioni di pulitura prima che l'oggetto stesso venga recuperato dalla procedura di Garbage Collection. (Ereditato da Object)
Metodo pubblico GetHashCode Funge da funzione hash per un determinato tipo. (Ereditato da Object)
Metodo pubblico GetType Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object)
Metodo protetto MemberwiseClone Consente di creare una copia dei riferimenti dell'oggetto Object corrente. (Ereditato da Object)
Metodo pubblico ToString Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object)
Metodo pubblico ValidateTable Questo metodo viene utilizzato per verificare che la tabella di attributi compilata contenga informazioni valide sugli attributi.

In alto

Note

Per creare una tabella di attributi, iniziare creando un'istanza della classe AttributeTableBuilder. Aggiungere metadati al generatore di tabelle di attributi chiamando gli overload AddCustomAttributes. Dopo aver aggiunto i metadati, produrre una tabella di attributi dal generatore di tabelle di attributi chiamando il metodo CreateTable. Poiché i metodi del generatore di tabelle di attributi supportano i delegati di callback, la creazione della tabella di attributi può essere posticipata finché non è necessaria.

Utilizzare la classe AttributeCallbackBuilder anziché la classe AttributeTableBuilder se si aggiungono molti attributi. Con questo approccio la creazione di attributi viene posticipata finché la finestra di progettazione non richiede i metadati per il tipo di destinazione.

Esempi

Nell'esempio di codice seguente viene illustrato come utilizzare la classe AttributeTableBuilder per creare e popolare una tabella di attributi. Per ulteriori informazioni, vedere Procedura dettagliata: creazione di uno strumento decorativo visuale in fase di progettazione.

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Reflection
Imports System.Text
Imports System.Windows.Media
Imports System.Windows.Controls
Imports System.Windows

Imports Microsoft.Windows.Design.Features
Imports 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(GetType(CustomControlLibrary.VisualStudio.Design.Metadata))> 

' 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.
Friend Class Metadata
    Implements IProvideAttributeTable

    ' Accessed by the designer to register any design-time metadata.
    Public ReadOnly Property AttributeTable() As AttributeTable _
        Implements IProvideAttributeTable.AttributeTable
        Get
            Dim builder As New AttributeTableBuilder()

            builder.AddCustomAttributes( _
                GetType(Button), _
                New DefaultPropertyAttribute("Content"))

            ' Apply the ReadOnlyAttribute to the Background property 
            ' of the Button class.
            builder.AddCustomAttributes( _
                GetType(Button), _
                "Background", _
                New ReadOnlyAttribute(True))

            Dim attributes As AttributeTable = builder.CreateTable()

            Return attributes
        End Get
    End Property

End Class
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
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();

                builder.AddCustomAttributes(
                    typeof(Button),
                    new DefaultPropertyAttribute("Content"));

                // Apply the ReadOnlyAttribute to the Background property 
                // of the Button class.
                builder.AddCustomAttributes(
                    typeof(Button),
                    "Background",
                    new ReadOnlyAttribute(true));

                AttributeTable attributes = builder.CreateTable();

                return attributes;
            }
        }
    }
}

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

Spazio dei nomi Microsoft.Windows.Design.Metadata

AttributeTable

AttributeCallbackBuilder