PropertyGrid 控件的默认内置编辑器
我似乎无法在任何地方找到这个问题的答案。 3.5 Framework PropertyGrid 控件中内置了哪些默认编辑器/转换器。 否则我可以向它扔什么对象类型并且它能够可靠地显示和编辑? 我发现了很多有关使用自定义编辑器的教程(我可能会在某个时候这样做)。 但现在在我的程序中,我允许用户创建自己的自定义属性,并且我想知道假设他们将在 PropertyGrid 中编辑它们,我应该允许哪些对象类型。
I can't seem to find the answer to this anywhere. What default editors/converters are building into 3.5 Framework PropertyGrid control. Otherwise what object types can I throw at it and it be able to reliably show and edit? I've found a lot of tutorials on using custom editors (which I may do at some point). But right now in my program I'm allowing the user to create their own custom properties and I want to know what object types I should allow assuming they will be editing them in a PropertyGrid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请记住,有一些非公开课程。
Bear in mind that there some non-public classes.
您可能想查看派生自 的类
UITypeEditor
(在System.Drawing.Design
命名空间)。 这些类型将作为参数传递给EditorAttribute< /code>
(在
System.ComponentModel命名空间
)。
您还可以查看该类型的元数据,以了解
EditorAttribute
的应用位置。 但是,不要在这里使用反射,因为这不是PropertyGrid
类 使用。而是使用
TypeDescriptor
类 获取类型属性的属性描述符(调用静态GetProperties
方法)。 然后,使用PropertyDescriptor
实例,调用GetEditor 方法
获取该属性的编辑器实例。
You might want to take a look at classes that derive from
UITypeEditor
(in theSystem.Drawing.Design
namespace). These types will be passed as parameters to theEditorAttribute
(in theSystem.ComponentModel
namespace).You can also look at the metadata for the type to see where the
EditorAttribute
is applied. However, do not use reflection here, as that is not what thePropertyGrid
class uses.Rather use the
TypeDescriptor
class to get property descriptors for the properties on the type (call the staticGetProperties
method). Then, with thePropertyDescriptor
instance, call theGetEditor
method to get an instance of the editor for that property.实际上,您可以将任何对象扔到 PropertyGrid 上。 它会自动做很多事情。 如果您想获得原生不提供的特殊编辑体验,则只需创建自定义 UI 类型编辑器。 即使在这种情况下,您也可以针对每个属性执行此操作,而不是针对整个对象。
You can actually throw any object at the PropertyGrid. It will do a lot of things automatically. You only need to create custom UI type editors if you want to have a special edit experience, which is not natively provided. And even in that case you do it per property and not for a whole object.
PropertyGrid 使用 TypeConverters,并且每个基本类型(以及基本类型的集合)都有 TypeConverters。
只要您使用一种基本类型或一组基本类型,属性网格就应该能够提供编辑 UI。
The PropertyGrid uses TypeConverters and there are TypeConverters for every primitive type (as well as collections of primitive types).
As long as you're using one of the primitive types or a collection of primitive types the property grid should be able to take care of providing an editing UI.
除了 UITypeEditors 之外,PropertyGrid 还能够显示具有 CanConvertFrom(String) 返回 true 的 TypeConverter 的任何对象。 您可以为特定对象类型实现自己的 TypeConverters 以实现此目的。
Besides UITypeEditors, the PropertyGrid is able to display any object with a TypeConverter that returns true for CanConvertFrom(String). You can implement your own TypeConverters for specific object types in order to accomplish this.