How to isolate a set of properties for use with a PropertyGrid?
I have several classes that inherit from WinForm UI controls. They have been extended with extra开发者_JAVA百科 properties which I need to be editable in a property grid control. The problem is, assigning an instance of this object to the property grid also displays the UI properties, like Color
, Text
, Dock
, etc. What would be the best way of isolating the specific properties so that these UI properties do not show up?
Thank you for your advice,
You my be able to override the properties you don't want and add [Browsable(false)]
. Other options:
- set the
.BrowsableAttributes
(http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.browsableattributes.aspx) and decorate the members you do want with your own attribute - write a
TypeConverter
and overrideGetProperties
; associate this converter with your type (or Te same via ICustomTypeConverter or TypeDescriptionProvider)
The BrowsableAttributes would be my first stab.
You could provide your own TypeDescriptor for your classes that only expose the properties you want editable.
Alternatively, if that's way too much work or the property grid is one in your own app, rather than the winforms designer one, you could create your own proxy classes that only expose the extra properties.
精彩评论