扩展 Visual Studio 2022 的 XAML 设计器属性窗口(Property Grid)

强 吴 0 信誉分
2025-08-14T01:31:49.4366667+00:00

扩展 Visual Studio 2022 的 XAML 设计器属性窗口(Property Grid),让某个类型的某个属性(比如 Human.Person)使用你自己的自定义编辑器,而不是默认的字符串/对象/集合编辑方式。是否支持这样做。有没有例子可以提供学习。

我尝试过 添加UITypeEditor ,无论是在源程序,还是在VSix 中,都不起作用。

public class Human
{
    [Editor(typeof(PersonEditor), typeof(UITypeEditor))]
    public Person Person { get; set; }
}

我也尝试下面的这种方式,也不成功。期待您的回复

public class Metadata : IRegisterMetadata
    {
        public void Register()
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();
            builder.AddCustomAttributes(
                typeof(Human),
                "Person",
                new EditorAttribute(typeof(PersonEditor), typeof(UITypeEditor))
            );
            MetadataStore.AddAttributeTable(builder.CreateTable());
        }
    }
开发人员技术 | Visual Studio | 扩展
0 个注释 无注释
{count} 票

你的答案

提问者可以将答案标记为“已接受”,版主可以将答案标记为“已推荐”,这有助于用户了解答案是否解决了提问者的问题。