AttributeTableBuilder.AddCallback Method

Adds a callback that is invoked when metadata for the specified type is needed.

Namespace:  Microsoft.Windows.Design.Metadata
Assembly:  Microsoft.Windows.Design (in Microsoft.Windows.Design.dll)

Syntax

'Declaration
Public Sub AddCallback ( _
    type As Type, _
    callback As AttributeCallback _
)
'Usage
Dim instance As AttributeTableBuilder 
Dim type As Type 
Dim callback As AttributeCallback

instance.AddCallback(type, callback)
public void AddCallback(
    Type type,
    AttributeCallback callback
)
public:
void AddCallback(
    Type^ type, 
    AttributeCallback^ callback
)
public function AddCallback(
    type : Type, 
    callback : AttributeCallback
)

Parameters

  • type
    Type: System.Type

    The type to add metadata attributes to.

Remarks

Callback can add metadata to the attribute table on demand, which is more efficient than adding metadata when the table is created.

Use the AddCallback method with the AttributeCallbackBuilder class when you are building a large attribute table.

Examples

The following code example shows how to use the AddCallback method and the AttributeTableBuilder class to create and populate an attribute table. This code example is part of a larger example provided for the AttributeCallbackBuilder class.

// 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. 
internal class Metadata : IRegisterMetadata
{
    // Called by the designer to register any design-time metadata. 
    public void Register()
    {
        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));

            PropertyDescriptorCollection properties =
                TypeDescriptor.GetProperties(typeof(Button));
            PropertyDescriptor pd = properties["Foreground"];
            callbackBuilder.AddCustomAttributes(
                pd,
                new ReadOnlyAttribute(true));

            callbackBuilder.AddCustomAttributes(
               Button.WidthProperty,
               new TypeConverterAttribute(typeof(LengthConverter)),
               new DescriptionAttribute("This is the width"));

            MemberInfo[] members = typeof(Button).GetMember("Height");
            callbackBuilder.AddCustomAttributes(
                members[0],
                new ReadOnlyAttribute(true));
        });

        MetadataStore.AddAttributeTable(builder.CreateTable());
    }
}

.NET Framework Security

See Also

Reference

AttributeTableBuilder Class

AttributeTableBuilder Members

Microsoft.Windows.Design.Metadata Namespace

AttributeTable

AttributeCallbackBuilder

Other Resources

Metadata Store