【问题标题】:How to make order of properties in a property grid differ from the order of properties in class declaration如何使属性网格中的属性顺序与类声明中的属性顺序不同
【发布时间】:2015-07-19 07:12:08
【问题描述】:

我想在 PropertyGrid 中显示以下类属性,而不是按照声明的顺序,而是指定的属性?有这样的属性吗?

作为:

一个 乙 C

谢谢。

    public class ApplicationConfiguration
    {
        public ApplicationConfiguration()
        {
        }
        public int A { get; set; }
        public int C { get; set; }
        public int B { get; set; }
}

【问题讨论】:

  • System.Runtime.Serialization.DataMemberAttribute 有 Order 属性

标签: c# properties attributes propertygrid


【解决方案1】:

如果您从 MVC/WCF 应用程序发送此对象,您可以使用如下所示的 DataMember 属性

public class ApplicationConfiguration
    {
        public ApplicationConfiguration()
        {
        }
        [DataMember(Order=1)]
        public int A { get; set; }
        [DataMember(Order = 3)]
        public int C { get; set; }
        [DataMember(Order = 2)]
        public int B { get; set; }
    }

【讨论】:

    【解决方案2】:

    在决定类的实例应如何出现在属性网格中时,您有很多选择。从Design-Time Attributes for Components 开始,然后从那里开始。

    请参阅Extending Design-Time Support 了解全局。最重要的是,只需添加[Category("categoryName")] 属性,您就可以轻松地使您的属性按类别分组显示。但是如果您需要它们以与声明顺序完全不同的顺序出现,那么您需要创建一个设计器。

    【讨论】:

      猜你喜欢
      • 2015-06-17
      • 1970-01-01
      • 2011-05-26
      • 2013-10-19
      • 2013-05-07
      • 2023-03-07
      • 1970-01-01
      • 2012-02-10
      相关资源
      最近更新 更多