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.
我似乎无法在任何地方找到答案。默认编辑器/转换器构建到3.5 Framework PropertyGrid控件中。否则我可以抛出哪些对象类型,它能够可靠地显示和编辑?我发现了很多关于使用自定义编辑器的教程(我可能会在某些时候这样做)。但是现在我的程序中我允许用户创建自己的自定义属性,我想知道我应该允许哪些对象类型,假设他们将在PropertyGrid中编辑它们。
5 个解决方案
#1
You might want to take a look at classes that derive from UITypeEditor
(in the System.Drawing.Design
namespace). These types will be passed as parameters to the EditorAttribute
(in the System.ComponentModel
namespace).
您可能希望查看从UITypeEditor派生的类(在System.Drawing.Design命名空间中)。这些类型将作为参数传递给EditorAttribute(在System.ComponentModel命名空间中)。
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 the PropertyGrid
class uses.
您还可以查看类型的元数据以查看EditorAttribute的应用位置。但是,不要在这里使用反射,因为这不是PropertyGrid类使用的。
Rather use the TypeDescriptor
class to get property descriptors for the properties on the type (call the static GetProperties
method). Then, with the PropertyDescriptor
instance, call the GetEditor
method to get an instance of the editor for that property.
而是使用TypeDescriptor类来获取类型属性的属性描述符(调用静态GetProperties方法)。然后,使用PropertyDescriptor实例,调用GetEditor方法以获取该属性的编辑器实例。
#2
Bear in mind that there some non-public classes.
请记住,有一些非公开课。
System.Object
System.Drawing.Design.UITypeEditor
System.ComponentModel.Design.CollectionEditor
System.ComponentModel.Design.ArrayEditor
System.Web.UI.Design.CollectionEditorBase
System.Web.UI.Design.WebControls.WizardStepCollectionEditor
System.Web.UI.Design.WebControls.EmbeddedMailObjectCollectionEditor
System.Web.UI.Design.WebControls.HotSpotCollectionEditor
System.Web.UI.Design.WebControls.ListItemsCollectionEditor
System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor
System.Web.UI.Design.WebControls.RoleGroupCollectionEditor
System.Web.UI.Design.WebControls.StyleCollectionEditor
System.Web.UI.Design.WebControls.SubMenuStyleCollectionEditor
System.Web.UI.Design.WebControls.TableCellsCollectionEditor
System.Web.UI.Design.WebControls.TableRowsCollectionEditor
System.ComponentModel.Design.BinaryEditor
System.ComponentModel.Design.DateTimeEditor
System.ComponentModel.Design.MultilineStringEditor
System.ComponentModel.Design.ObjectSelectorEditor
System.Windows.Forms.Design.AnchorEditor
System.Windows.Forms.Design.BorderSidesEditor
System.Windows.Forms.Design.DockEditor
System.Windows.Forms.Design.FileNameEditor
System.Windows.Forms.Design.FolderNameEditor
System.Windows.Forms.Design.ShortcutKeysEditor
System.Web.UI.Design.ConnectionStringEditor
System.Web.UI.Design.DataBindingCollectionEditor
System.Web.UI.Design.ExpressionsCollectionEditor
System.Web.UI.Design.UrlEditor
System.Web.UI.Design.XmlFileEditor
System.Web.UI.Design.WebControls.DataGridColumnCollectionEditor
System.Web.UI.Design.WebControls.DataControlFieldTypeEditor
System.Web.UI.Design.WebControls.MenuBindingsEditor
System.Web.UI.Design.WebControls.MenuItemCollectionEditor
System.Web.UI.Design.WebControls.ParameterCollectionEditor
System.Web.UI.Design.WebControls.RegexTypeEditor
System.Web.UI.Design.WebControls.TreeNodeCollectionEditor
System.Web.UI.Design.WebControls.TreeViewBindingsEditor
System.Web.UI.Design.WebControls.DataPagerFieldTypeEditor
System.Messaging.Design.QueuePathEditor
System.Drawing.Design.ImageEditor
System.Drawing.Design.ColorEditor
System.Drawing.Design.ContentAlignmentEditor
System.Drawing.Design.CursorEditor
System.Drawing.Design.FontEditor
System.Drawing.Design.FontNameEditor
System.Drawing.Design.IconEditor
System.Workflow.ComponentModel.Design.TypeBrowserEditor
System.Workflow.ComponentModel.Design.BindUITypeEditor
#3
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上抛出任何对象。它会自动完成很多事情。如果您希望获得本机提供的特殊编辑体验,则只需创建自定义UI类型编辑器。即使在这种情况下,你按照属性而不是整个对象来做。
#4
The PropertyGrid uses TypeConverters and there are TypeConverters for every primitive type (as well as collections of primitive types).
PropertyGrid使用TypeConverters,并且每种基本类型(以及基本类型的集合)都有TypeConverters。
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.
只要您使用其中一种基本类型或基本类型集合,属性网格就应该能够提供编辑UI。
#5
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.
除了UITypeEditors之外,PropertyGrid还能够显示任何带有TypeConverter的对象,该对象为CanConvertFrom(String)返回true。您可以为特定对象类型实现自己的TypeConverters,以实现此目的。
#1
You might want to take a look at classes that derive from UITypeEditor
(in the System.Drawing.Design
namespace). These types will be passed as parameters to the EditorAttribute
(in the System.ComponentModel
namespace).
您可能希望查看从UITypeEditor派生的类(在System.Drawing.Design命名空间中)。这些类型将作为参数传递给EditorAttribute(在System.ComponentModel命名空间中)。
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 the PropertyGrid
class uses.
您还可以查看类型的元数据以查看EditorAttribute的应用位置。但是,不要在这里使用反射,因为这不是PropertyGrid类使用的。
Rather use the TypeDescriptor
class to get property descriptors for the properties on the type (call the static GetProperties
method). Then, with the PropertyDescriptor
instance, call the GetEditor
method to get an instance of the editor for that property.
而是使用TypeDescriptor类来获取类型属性的属性描述符(调用静态GetProperties方法)。然后,使用PropertyDescriptor实例,调用GetEditor方法以获取该属性的编辑器实例。
#2
Bear in mind that there some non-public classes.
请记住,有一些非公开课。
System.Object
System.Drawing.Design.UITypeEditor
System.ComponentModel.Design.CollectionEditor
System.ComponentModel.Design.ArrayEditor
System.Web.UI.Design.CollectionEditorBase
System.Web.UI.Design.WebControls.WizardStepCollectionEditor
System.Web.UI.Design.WebControls.EmbeddedMailObjectCollectionEditor
System.Web.UI.Design.WebControls.HotSpotCollectionEditor
System.Web.UI.Design.WebControls.ListItemsCollectionEditor
System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor
System.Web.UI.Design.WebControls.RoleGroupCollectionEditor
System.Web.UI.Design.WebControls.StyleCollectionEditor
System.Web.UI.Design.WebControls.SubMenuStyleCollectionEditor
System.Web.UI.Design.WebControls.TableCellsCollectionEditor
System.Web.UI.Design.WebControls.TableRowsCollectionEditor
System.ComponentModel.Design.BinaryEditor
System.ComponentModel.Design.DateTimeEditor
System.ComponentModel.Design.MultilineStringEditor
System.ComponentModel.Design.ObjectSelectorEditor
System.Windows.Forms.Design.AnchorEditor
System.Windows.Forms.Design.BorderSidesEditor
System.Windows.Forms.Design.DockEditor
System.Windows.Forms.Design.FileNameEditor
System.Windows.Forms.Design.FolderNameEditor
System.Windows.Forms.Design.ShortcutKeysEditor
System.Web.UI.Design.ConnectionStringEditor
System.Web.UI.Design.DataBindingCollectionEditor
System.Web.UI.Design.ExpressionsCollectionEditor
System.Web.UI.Design.UrlEditor
System.Web.UI.Design.XmlFileEditor
System.Web.UI.Design.WebControls.DataGridColumnCollectionEditor
System.Web.UI.Design.WebControls.DataControlFieldTypeEditor
System.Web.UI.Design.WebControls.MenuBindingsEditor
System.Web.UI.Design.WebControls.MenuItemCollectionEditor
System.Web.UI.Design.WebControls.ParameterCollectionEditor
System.Web.UI.Design.WebControls.RegexTypeEditor
System.Web.UI.Design.WebControls.TreeNodeCollectionEditor
System.Web.UI.Design.WebControls.TreeViewBindingsEditor
System.Web.UI.Design.WebControls.DataPagerFieldTypeEditor
System.Messaging.Design.QueuePathEditor
System.Drawing.Design.ImageEditor
System.Drawing.Design.ColorEditor
System.Drawing.Design.ContentAlignmentEditor
System.Drawing.Design.CursorEditor
System.Drawing.Design.FontEditor
System.Drawing.Design.FontNameEditor
System.Drawing.Design.IconEditor
System.Workflow.ComponentModel.Design.TypeBrowserEditor
System.Workflow.ComponentModel.Design.BindUITypeEditor
#3
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上抛出任何对象。它会自动完成很多事情。如果您希望获得本机提供的特殊编辑体验,则只需创建自定义UI类型编辑器。即使在这种情况下,你按照属性而不是整个对象来做。
#4
The PropertyGrid uses TypeConverters and there are TypeConverters for every primitive type (as well as collections of primitive types).
PropertyGrid使用TypeConverters,并且每种基本类型(以及基本类型的集合)都有TypeConverters。
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.
只要您使用其中一种基本类型或基本类型集合,属性网格就应该能够提供编辑UI。
#5
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.
除了UITypeEditors之外,PropertyGrid还能够显示任何带有TypeConverter的对象,该对象为CanConvertFrom(String)返回true。您可以为特定对象类型实现自己的TypeConverters,以实现此目的。