This documentation is archived and is not being maintained.

IProvideAttributeTable Interface

Visual Studio 2010

Defines a class that provides an attribute table.

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

public interface IProvideAttributeTable

The IProvideAttributeTable type exposes the following members.

  NameDescription
Public propertyAttributeTableGets the attribute table provided by the class.
Top

Implement the IProvideAttributeTable interface to provide design-time metadata attributes to a design tool, such as Visual Studio and Expression Blend. For more information, see AttributeTable and Providing Design-time Metadata.

The following code example shows how to implement the IProvideAttributeTable interface to create and populate an attribute table. For more information, see Walkthrough: Creating a Design-time Adorner.


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

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

                AttributeTable attributes = builder.CreateTable();

                bool hasCustomAttributes = attributes.ContainsAttributes(typeof(Button));

                IEnumerable<Type> types = attributes.AttributedTypes;

                // The following code shows how to retrieve custom attributes
                // using the GetCustomAttributes method overloads.
                IEnumerable attrs0 = attributes.GetCustomAttributes(typeof(Button));

                IEnumerable attrs1 = attributes.GetCustomAttributes(
                    typeof(Button),
                    "Background");

                return attributes;
            }
        }
    }
}


Show: