【发布时间】:2019-12-24 07:50:04
【问题描述】:
如example here 所示,我想要实现的是在 Xceed PropertyGrid 控件中排序类别。
如该示例所示(此处复制以供参考),您可以在编译时通过向类添加属性来指定此信息,如下所示...
[CategoryOrder("General", 1)]
[CategoryOrder("Advanced", 2)]
[CategoryOrder("Other", 3)]
public class MyClass {
[Category("General")]
public string Property1 { get; set; }
[Category("Advanced")]
public int Property2 { get; set; }
[Category("Other")]
public double Property3 { get; set; }
[Category("General")]
public string Property4 { get; set; }
[Category("Advanced")]
public int Property5 { get; set; }
[Category("Other")]
public double Property6 { get; set; }
}
它会像这样出现在PropertyGrid...
然而,我想要做的是在运行时设置 CategoryOrderAttribute 值。这是我正在尝试的方法,但它不起作用......
// Note: This gets executed *prior* to assignment to the PropertyGrid
TypeDescriptor.AddAttributes(typeof(MyClass),
new CategoryOrderAttribute("General", 1),
new CategoryOrderAttribute("Advanced", 2),
new CategoryOrderAttribute("Other", 3)
);
就像我说的那样,这不起作用,类别仍按字母顺序显示。知道为什么这不起作用吗?
【问题讨论】:
标签: c# wpf wpftoolkit propertygrid xceed