ToolboxBrowsableAttribute 类

更新:2007 年 11 月

指定控件是否在设计器的工具箱浏览器中显示。

命名空间:  Microsoft.Windows.Design
程序集:  Microsoft.Windows.Design(在 Microsoft.Windows.Design.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public NotInheritable Class ToolboxBrowsableAttribute _
    Inherits Attribute
用法
Dim instance As ToolboxBrowsableAttribute
[AttributeUsageAttribute(AttributeTargets.Class)]
public sealed class ToolboxBrowsableAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class)]
public ref class ToolboxBrowsableAttribute sealed : public Attribute
public final class ToolboxBrowsableAttribute extends Attribute

备注

使用 ToolboxBrowsableAttribute 可以指定何时控件在 Visual Studio Windows Presentation Foundation (WPF) 设计器的“选择工具箱项”对话框或者 Microsoft Blend 的“资产库”中显示。

示例

下面的代码示例演示如何使用 ToolboxBrowsableAttribute 来启用自定义控件在设计器的工具箱浏览器中的可见性。

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.ComponentModel
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

Public Class ButtonWithDesignTime
    Inherits Button
End 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.
Friend Class Metadata
    Implements IRegisterMetadata

    ' Called by the designer to register any design-time metadata.
    Public Sub Register() Implements IRegisterMetadata.Register
        Dim builder As New AttributeTableBuilder()

        builder.AddCustomAttributes( _
            GetType(ButtonWithDesignTime), _
            New ToolboxBrowsableAttribute(True))

        MetadataStore.AddAttributeTable(builder.CreateTable())

    End Sub
End Class
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;

using Microsoft.Windows.Design;
using Microsoft.Windows.Design.Features;
using Microsoft.Windows.Design.Metadata;

namespace CustomControlLibrary.Design
{
    public class ButtonWithDesignTime : Button
    {
    }

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

            builder.AddCustomAttributes(
                typeof(ButtonWithDesignTime),
                new ToolboxBrowsableAttribute(true));

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

继承层次结构

System.Object
  System.Attribute
    Microsoft.Windows.Design.ToolboxBrowsableAttribute

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

另请参见

参考

ToolboxBrowsableAttribute 成员

Microsoft.Windows.Design 命名空间

AttributeTableBuilder

其他资源

演练:创建设计时装饰器