.NET PropertyGrid 中的多个类别对于属性不可见
我有一个包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定如果将多个属性分配给 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.