.NET PropertyGrid 中的多个类别对于属性不可见

发布于 2024-10-14 19:01:56 字数 1443 浏览 1 评论 0原文

我有一个包含 2 个类别的 PropertyGrid:“客户测试 1”和“客户测试 2”

如果我在 BrowseableAttributes 中只有一个 CategoryAttribute,则会显示一个类别。 如果我在 BrowseableAttributes 中有两个/两个 CategoryAttribute,则不会显示任何类别。

为什么呢?

public class Customer
    {
        [DisplayName("first name...:")]
        [Category("Customer Test 1")]
        public string FirstName { get; set; }

        [DisplayName("number...")]
        [Category("Customer Test 1")]
        public int Number { get; set; }

        [DisplayName("wage...:")]
        [Category("Customer Test 2")]
        public int Wage { get; set; }

        [DisplayName("description...:")]
        [Category("Customer Test 1")]
        public string  Desc { get; set; }

        [DisplayName("shit...:")]
        [Category("Customer Test 1")]
        public string Nonsens { get; set; }      
    }

    public Form1()
            {
                InitializeComponent();

                Attribute[] attributes = new Attribute[]{ new CategoryAttribute("Customer Test 1"), new CategoryAttribute("Customer Test 2") };
                propertyGrid1.BrowsableAttributes = new AttributeCollection(attributes);

                propertyGrid1.PropertySort = PropertySort.Categorized;
                propertyGrid1.ToolbarVisible = true;
                propertyGrid1.SelectedObject = new Customer() { FirstName = "Bernd", Number = 100, Desc = 

"steine", Wage = 3333, Nonsens = "crap" };
        }

I have a PropertyGrid with 2 Categories: "Customer Test 1" and "Customer Test 2"

If I have only ONE CategoryAttribute in the BrowseableAttributes ONE Category is shown.
If I have BOTH/TWO CategoryAttribute`s in the BrowseableAttributes NONE category is shown.

Why that?

public class Customer
    {
        [DisplayName("first name...:")]
        [Category("Customer Test 1")]
        public string FirstName { get; set; }

        [DisplayName("number...")]
        [Category("Customer Test 1")]
        public int Number { get; set; }

        [DisplayName("wage...:")]
        [Category("Customer Test 2")]
        public int Wage { get; set; }

        [DisplayName("description...:")]
        [Category("Customer Test 1")]
        public string  Desc { get; set; }

        [DisplayName("shit...:")]
        [Category("Customer Test 1")]
        public string Nonsens { get; set; }      
    }

    public Form1()
            {
                InitializeComponent();

                Attribute[] attributes = new Attribute[]{ new CategoryAttribute("Customer Test 1"), new CategoryAttribute("Customer Test 2") };
                propertyGrid1.BrowsableAttributes = new AttributeCollection(attributes);

                propertyGrid1.PropertySort = PropertySort.Categorized;
                propertyGrid1.ToolbarVisible = true;
                propertyGrid1.SelectedObject = new Customer() { FirstName = "Bernd", Number = 100, Desc = 

"steine", Wage = 3333, Nonsens = "crap" };
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抽个烟儿 2024-10-21 19:01:56

您确定如果将多个属性分配给 BrowsableAttributes,属性只需具有 1 个匹配属性而不是全部?

换句话说,BrowsableAttributes 可以充当过滤器,在属性上使用 AND 运算符而不是 OR。但我必须承认我自己还没有尝试过。

Are you sure that if you assign multiple attributes to BrowsableAttributes, properties need to have only 1 matching attribute and not ALL of them?

In other words, BrowsableAttributes might act as a filter using and AND operator on the attributes instead of an OR. But I have to admit that I have not tried this myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文