AttributeTableBuilder Class
Creates an attribute table that defines design-time metadata.
Inheritance Hierarchy
System.Object
Microsoft.Windows.Design.Metadata.AttributeTableBuilder
Namespace: Microsoft.Windows.Design.Metadata
Assembly: Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)
Syntax
'Declaration
Public Class AttributeTableBuilder
public class AttributeTableBuilder
public ref class AttributeTableBuilder
type AttributeTableBuilder = class end
public class AttributeTableBuilder
The AttributeTableBuilder type exposes the following members.
Constructors
Name | Description | |
---|---|---|
AttributeTableBuilder | Initializes a new instance of the AttributeTableBuilder class. |
Top
Methods
Name | Description | |
---|---|---|
AddCallback | Adds a callback that is invoked when metadata for the specified type is needed. | |
AddCustomAttributes(Assembly, array<Attribute[]) | Adds the contents of the provided attributes array to the table builder. | |
AddCustomAttributes(Type, array<Attribute[]) | Adds the contents of the provided attributes to the table builder. | |
AddCustomAttributes(Type, String, array<Attribute[]) | Adds attributes to the member with the specified name. | |
AddTable | Adds the contents of the provided attribute table to the table builder. | |
CreateTable | Creates an attribute table that contains all the attribute definitions provided through AddCustomAttributes calls. | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
ValidateTable | This method is used to verify the attribute table which is being built contains valid attribute information. |
Top
Remarks
To create an attribute table, you start by creating an instance of the AttributeTableBuilder class. You add metadata to the attribute table builder by calling the AddCustomAttributes overloads. When you are finished adding metadata, you produce an attribute table from the attribute table builder by calling the CreateTable method. The attribute table builder methods support callback delegates, so the creation of the attribute table can be deferred until needed.
Use the AttributeCallbackBuilder class instead of the AttributeTableBuilder class if you are adding many attributes. This approach defers the creation of attributes until the designer requests metadata for the target type.
Examples
The following code example shows how to use the AttributeTableBuilder class to create and populate an attribute table. For more information, see Walkthrough: Creating a Design-time Adorner.
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;
}
}
}
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.