How to add a service to the type descriptor context of a property grid in .Net?
Posted
by Jules
on Stack Overflow
See other posts from Stack Overflow
or by Jules
Published on 2010-04-13T19:52:27Z
Indexed on
2010/04/13
20:33 UTC
Read the original article
Hit count: 258
I have an app that allows the user to choose an image, at design time, either as a straight image, or from an image list.
All cool so far, except that this is not happening from the visual studio property browser, its happening from a property grid that is a part of a type editor.
My problem is, both the image picker (actually resource picker), and the imagelist type converter rely on some design-time services to get the job done. In the case of imagelist, its the IReferenceService and in the case of the resource picker its a service called _DTE.
In the first instance of an edit from the visual studio property browser, I could get a reference to these services but (1) how can I add them to the type descriptor context of my property grid?
It would be better, for future proofing, if I could just copy a reference to all of the services in the type descriptor context. (2) Where does the property browser get these services from in the first place?
ETA: I still don't know how to do it, but I now know it is possible.
(1) Sub-class control and add a property whose type is an array of buttons.
(2) Add it to a form.
(3) Select the new control on the design service and edit the new property in the property browser.
(4) The collection editor dialog pops-up
(5) Add a button
(6) Edit image and image list - the type editor and type converter, respectively, behave as they should.
© Stack Overflow or respective owner