AttributeCallbackBuilder Class
An instance of this class is passed to callback delegates to lazily populate the attributes for a type.
Inheritance Hierarchy
System.Object
Microsoft.Windows.Design.Metadata.AttributeCallbackBuilder
Namespace: Microsoft.Windows.Design.Metadata
Assembly: Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)
Syntax
'Declaration
Public NotInheritable Class AttributeCallbackBuilder
public sealed class AttributeCallbackBuilder
public ref class AttributeCallbackBuilder sealed
[<Sealed>]
type AttributeCallbackBuilder = class end
public final class AttributeCallbackBuilder
The AttributeCallbackBuilder type exposes the following members.
Properties
Name | Description | |
---|---|---|
CallbackType | Gets the type this callback is being invoked for. |
Top
Methods
Name | Description | |
---|---|---|
AddCustomAttributes(array<Attribute[]) | Adds the contents of the specified attributes to this builder. | |
AddCustomAttributes(String, array<Attribute[]) | Adds attributes to the member with the specified name. | |
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.) |
Top
Remarks
Use the AttributeCallbackBuilder to populate an AttributeTable on demand. This is especially important for attribute tables that hold many attributes. If you are specifying only a few attributes for a type, use the AttributeTableBuilder by itself.
Using the delegate format, no attributes are constructed until metadata for the target type is requested by the designer. The AttributeTableBuilder transfers this callback information into the AttributeTable and preserves it. Therefore, these callback delegates are only invoked on demand. Once invoked, their results are cached by the AttributeTable.
Enable on-demand attribute creation by using the AddCallback method.
Examples
The following code example shows how to create and populate an attribute table by using the AttributeCallbackBuilder class.
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();
}
}
}
}
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.
See Also
Reference
Microsoft.Windows.Design.Metadata Namespace