如何对控件的属性进行分类以显示在 Blend 和 Visual studio 设计器中的适当部分?

How can I categorize properties of my control to appear in appropriate sections in Blend and Visual studio designer?

在以前的 XAML 技术中,您可以将 CategoryAttribute 添加到依赖项 属性 中,它将出现在 Blend 的属性 window 和 Visual Studio.

例如,我想在自定义控件中添加一个新的 Brush 属性 并使其显示在 "Appearance" 类别下。

[Category("Appearance")]
public Brush MyAwesomeBrush { get {...} set {...} }

有没有办法为 Windows 商店应用程序 (Win8/Win10/Phone/etc) 执行此操作?

根据 this post,Windows 商店应用等不支持它

你想做就做。

将以下内容 class 添加到您的项目中(保留命名空间,一切都完全如此):

namespace System.ComponentModel
{
    [AttributeUsage(AttributeTargets.All)]
    public class CategoryAttribute : Attribute
    {
        public CategoryAttribute(string category)
        {
            Category = category;
        }

        public string Category { get; private set; }

        public override bool Equals(object obj)
        {
            if (obj == this)
                return true;

            var other = obj as CategoryAttribute;
            return other != null && other.Category == Category;
        }

        public override int GetHashCode()
        {
            return Category.GetHashCode();
        }
    }
}

这样使用:

和tada.wav,有效:)