CategoryEditor 类

更新:2007 年 11 月

用于创建自定义类别编辑器的抽象类。

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

语法

声明
Public MustInherit Class CategoryEditor
用法
Dim instance As CategoryEditor
public abstract class CategoryEditor
public ref class CategoryEditor abstract
public abstract class CategoryEditor

备注

从此类派生,以便为属性浏览器宿主中的一组属性提供自定义 CategoryEditor。此类表示用于编辑一组相关属性(如“文本”类别中的属性)的自定义用户界面。

TargetCategory 属性指示此编辑器应编辑的相关属性的类别。例如,“属性”窗口中的“文本”类别下显示了多个文本相关属性。如果编辑器设计用来编辑这些属性,则 TargetCategory 属性返回“Text”。

EditorTemplate 属性返回此编辑器的可视化界面的 XAML 模板。这通常是在项目中其他位置的 ResourceDictionary 中提供的。

请注意,在 CategoryEditor 将由设计器使用之前,必须先将其注册。有关更多信息,请参见 IRegisterMetadata

示例

下面的代码示例演示如何使用 CategoryEditor 类。有关更多信息,请参见演练:创建类别编辑器

Public Class TextCategoryEditor
    Inherits CategoryEditor

    ' The EditorResources class in this example inherits ResourceDirectory and
    ' contains the template for the category editor. This would be defined in 
    ' an associated XAML file named EditorResources.xaml
    Private res As New EditorResources()
    Public Overrides Function ConsumesProperty(ByVal prop As PropertyEntry) As Boolean
        Return True
    End Function

    Public Overrides ReadOnly Property EditorTemplate() As System.Windows.DataTemplate
        Get
            Return CType(res("TextCategoryEditorTemplate"), DataTemplate)
        End Get
    End Property

    Public Overrides Function GetImage(ByVal desiredSize As System.Windows.Size) As Object
        Return Nothing
    End Function

    Public Overrides ReadOnly Property TargetCategory() As String
        Get
            Return "Text"
        End Get
    End Property
End Class
public class TextCategoryEditor : CategoryEditor
{

    // The EditorResources class in this example inherits ResourceDictionary 
    // and contains template for the category editor. This would be 
    // defined in an associated XAML file named EditorResources.xaml
    private EditorResources res = new EditorResources();
    public TextCategoryEditor()
    {
    }

    public override bool ConsumesProperty(PropertyEntry property)
    {
        return true;
    }

    public override DataTemplate EditorTemplate
    {
        get
        {
            return res["TextCategoryEditorTemplate"] as DataTemplate;
        }
    }

    public override object GetImage(Size desiredSize)
    {
        return null;
    }

    public override string TargetCategory
    {
        get { return "Text"; }
    }
}

继承层次结构

System.Object
  Microsoft.Windows.Design.PropertyEditing.CategoryEditor

线程安全

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

另请参见

参考

CategoryEditor 成员

Microsoft.Windows.Design.PropertyEditing 命名空间

其他资源

属性编辑体系结构

WPF 设计器扩展性