AttributeTableBuilder.AddCallback - метод
Добавление обратного вызова, который выполняется, если для заданного типа требуются метаданные.
Пространство имен: Microsoft.Windows.Design.Metadata
Сборка: Microsoft.Windows.Design.Extensibility (в Microsoft.Windows.Design.Extensibility.dll)
Синтаксис
'Декларация
Public Sub AddCallback ( _
type As Type, _
callback As AttributeCallback _
)
public void AddCallback(
Type type,
AttributeCallback callback
)
public:
void AddCallback(
Type^ type,
AttributeCallback^ callback
)
member AddCallback :
type:Type *
callback:AttributeCallback -> unit
public function AddCallback(
type : Type,
callback : AttributeCallback
)
Параметры
- type
Тип: System.Type
Тип, к которому добавляются атрибуты метаданных.
- callback
Тип: Microsoft.Windows.Design.Metadata.AttributeCallback
Метод AttributeCallback, добавляющий метаданные к типу Type.
Заметки
Метод Callback обеспечивает добавление метаданных в таблицу атрибутов по требованию, что более эффективно, чем добавление метаданных при создании таблицы.
Метод AddCallback рекомендуется использовать совместно с классом AttributeCallbackBuilder при создании больших таблиц атрибутов.
Примеры
В следующем примере показано, как использовать метод AddCallback и класс AttributeTableBuilder для создания и заполнения таблицы атрибутов. Данный пример кода является частью большого примера, приведенного в описании класса AttributeCallbackBuilder.
// 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();
}
}
}
Безопасность платформы .NET Framework
- Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в разделе Использование библиотек из не вполне надежного кода.