实现ICustomTypeDescriptor [英] Implementing ICustomTypeDescriptor

查看:52
本文介绍了实现ICustomTypeDescriptor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现ICustomTypeDescriptor,以便我可以按逻辑顺序显示类的属性,而不是按照字母顺序在PropertyGrid控件中显示。  在实现GetProperties方法时,我首先创建了一个新的PropertyDescriptorCollection。 然后我发现我无法为这个新集合添加属性,因为PropertyDescriptor的构造函数受到保护。


如果构造函数受到保护,如何创建PropertyDescriptor的实例?


这是我到目前为止所做的,显然不起作用:


PropertyDescriptor [] properties = new PropertyDescriptor [1];
属性[0] =
new PropertyDescriptor ();
properties [0] .Category =
"测试类别" ;
属性[0]。描述=
"测试说明" ;
属性[0] .DisplayName =
"测试属性" ;
属性[0] .Name =
"TestProperty" ;
PropertyDescriptorCollection props = new PropertyDescriptorCollection (properties);

解决方案

检查链接,它可能会有所帮助。


http://social.msdn.microsoft.com/Forums /窗/ EN-US / 2660e771-8a0c-43c0-B090-eba94125c4bc /实施-icustomtypedescriptor?论坛= WinForms的


I am trying to implement ICustomTypeDescriptor so that I can display the properties of a class in a logical order rather than in alphabetical order in the PropertyGrid control.   While implementing the GetProperties method, I started by creating a new PropertyDescriptorCollection.  I then discovered that I cant add properties to this new collection because the constructor of PropertyDescriptor is protected.

How do I create instances of PropertyDescriptor's if the constructor is protected?

here is what i have so far, which obviously doesnt work:

PropertyDescriptor[] properties = new PropertyDescriptor[1];
properties[0] =
new PropertyDescriptor();
properties[0].Category =
"test category";
properties[0].Description =
"Test description";
properties[0].DisplayName =
"Test Property";
properties[0].Name =
"TestProperty";
PropertyDescriptorCollection props = new PropertyDescriptorCollection(properties);

解决方案

Check the link, it may be helpfull.

http://social.msdn.microsoft.com/Forums/windows/en-US/2660e771-8a0c-43c0-b090-eba94125c4bc/implementing-icustomtypedescriptor?forum=winforms


这篇关于实现ICustomTypeDescriptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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