如何在Xceed PropertyGrid中以编程方式对类别进行排序? [英] How can you programmatically order categories in the Xceed PropertyGrid?

查看:275
本文介绍了如何在Xceed PropertyGrid中以编程方式对类别进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的示例所示,我要实现的目标是在Xceed PropertyGrid中排序类别控制.

As shown in the example here, what I'm trying to achieve is ordering categories in the Xceed PropertyGrid control.

如该示例所示(在此处复制以供参考),您可以在编译时通过向类添加属性来指定此信息,例如...

As that example shows (copied here for reference), you can specify this information at compile-time by adding attributes to the class, like so...

[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中出现...

And it would appear in the PropertyGrid like this...

但是我想做的是在运行时设置CategoryOrderAttribute值.这是我正在尝试的方法,但是不起作用...

What I'm trying to do however is set the CategoryOrderAttribute values at runtime. Here's what I'm trying, but it's not working...

// 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)
);

就像我说的那样,这行不通,并且类别仍然按字母顺序显示.知道为什么这行不通吗?

Like I said, this doesn't work and the categories still appear in alphabetical order. Any idea why that doesn't work?

推荐答案

原来,有两个bug.一,它们没有覆盖CategoryOrderAttribute中的TypeID,二,它们没有使用TypeDescriptor.GetAttributes.我已经提交了两个错误……

Turns out there are two bugs in the source. One, they aren't overriding TypeID in CategoryOrderAttribute, and two, they aren't using TypeDescriptor.GetAttributes. I've submitted bugs for both...

https://github.com/xceedsoftware/wpftoolkit/issues/1522

这篇关于如何在Xceed PropertyGrid中以编程方式对类别进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆