共用方式為


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,指定控制項是否可以在 Windows Presentation Foundation (WPF) Designer for Visual Studio 的 [選擇工具箱項目] 對話方塊或 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

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

ToolboxBrowsableAttribute 成員

Microsoft.Windows.Design 命名空間

AttributeTableBuilder

其他資源

逐步解說:建立設計階段裝飾項