Поделиться через


AttributeCallback - делегат

Вызывается, если для типа требуются атрибуты.

Пространство имен:  Microsoft.Windows.Design.Metadata
Сборка:  Microsoft.Windows.Design.Extensibility (в Microsoft.Windows.Design.Extensibility.dll)

Синтаксис

'Декларация
Public Delegate Sub AttributeCallback ( _
    builder As AttributeCallbackBuilder _
)
public delegate void AttributeCallback(
    AttributeCallbackBuilder builder
)
public delegate void AttributeCallback(
    AttributeCallbackBuilder^ builder
)
type AttributeCallback = 
    delegate of 
        builder:AttributeCallbackBuilder -> unit
JScript не поддерживает делегаты.

Параметры

Заметки

Делегат класса AttributeCallback рекомендуется использовать для заполнения больших таблиц атрибутов. При использовании шаблона обратного вызова заполнение таблицы атрибутов откладывается до тех пор, пока конструктору не потребуются метаданные времени разработки для типа.

Примеры

В следующем примере показано, как создать и заполнить таблицу атрибутов с использованием класса AttributeCallbackBuilder.

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

См. также

Ссылки

Microsoft.Windows.Design.Metadata - пространство имен

AttributeTableBuilder

AddCallback

AttributeTable

Другие ресурсы

Пошаговое руководство. Создание графического элемента времени разработки

Общее представление о расширяемости конструктора WPF