我正在使用 Xceed的PropertyGrid 来显示某些元素的特征。元素有不同的类别,如:General,Advanced,Others,Special。在这里,我发现Xceed的propertygrid按字母顺序对类别和属性进行排序。我能够使用[PropertyOrder(n)]
对类别中的属性进行排序。我还想对类别进行排序,我尝试使用CategoryOrder
[CategoryOrder("General", 0)]
,但它显示以下错误:
错误2属性'CategoryOrder'在此声明类型上无效。它仅对“类”声明有效。
我使用它错了吗? 下面提供的代码只是一个展示我如何使用它的示例。
[Category("General")]
[CategoryOrder("General", 0)]
[DisplayName("XValue")]
[Description("Value of X-Coordinate")]
[ReadOnly(true)]
[PropertyOrder(1)]
[Category("Advanced")]
[CategoryOrder("Advanced", 1)]
[DisplayName("Collision")]
[Description("Collision")]
[ReadOnly(true)]
[PropertyOrder(1)]
[Category("Others")]
[CategoryOrder("Others", 3)]
[DisplayName("Traffic")]
[Description("Traffic at a point")]
[ReadOnly(true)]
[PropertyOrder(1)]
[Category("Special")]
[CategoryOrder("Special", 2)]
[DisplayName("Special cases")]
[Description("Contains the special cases and files")]
[PropertyOrder(1)]
答案 0 :(得分:6)
以下是如何使用它的示例:
[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; }
}