IProvideAttributeTable 接口
[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]
定义一个提供特性表的类。
命名空间: Microsoft.Windows.Design.Metadata
程序集: Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)
语法
声明
Public Interface IProvideAttributeTable
public interface IProvideAttributeTable
public interface class IProvideAttributeTable
type IProvideAttributeTable = interface end
public interface IProvideAttributeTable
IProvideAttributeTable 类型公开以下成员。
属性
名称 | 说明 | |
---|---|---|
AttributeTable | 获取由该类提供的特性表。 |
页首
备注
实现 IProvideAttributeTable 接口以向设计工具提供设计时元数据特性,如 Visual Studio 和 Expression Blend。 有关更多信息,请参见AttributeTable和 提供设计时元数据。
示例
下面的代码示例演示如何使用 IProvideAttributeTable 接口以创建和填充特性表。 有关更多信息,请参见演练:创建设计时装饰器。
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
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 IProvideAttributeTable. If found, designers instantiate
' this class and access its AttributeTable property 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()
' 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()
Dim hasCustomAttributes As Boolean = attributes.ContainsAttributes(GetType(Button))
Dim types As IEnumerable(Of Type) = attributes.AttributedTypes
' The following code shows how to retrieve custom attributes
' using the GetCustomAttributes method overloads.
Dim attrs0 As IEnumerable = attributes.GetCustomAttributes(GetType(Button))
Dim attrs1 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), "Background")
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();
// 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;
}
}
}
}
请参见
参考
Microsoft.Windows.Design.Metadata 命名空间