I’ve officially released my property grid extension project, called "ShinyDesign," under the open-source BSD-like license. I blogged about this project just a few days ago, and I’m excited to be releasing it to the public domain.
In truth, there are some ugly hacks, and I’m sure I could have done a better job commenting on what I did. All told, the multiple-tab hack is probably the worst. The Windows Forms PropertyGrid does not allow you to directly add additional property tabs; rather, you add Type objects that represent the tabs. The good news is that there’s a virtual method that allows you to create the tab given the Type. The bad news is that the PropertyGrid will block you from creating additional tabs of the same Type. The consequent solution is that, in the PropertyGridEx control, if additional tabs are used, I dynamically define an assembly and type for each PropertyTab being created. The type is a cleaned-up version of the tab name, and the closed types are cached (if the same property tab name is used on the same PropertyGridEx in the future). The types are then used to close a generic ExtensionPropertyTab<T> class, and the type parameter is then ignored from there. Oh, the things we do!
The ShinyDesign documentation is available on the web as well as a direct download. The code is also available from my website, and details for accessing it through Subversion are also provided.
Hopefully, people find it easy to use – simply drop the PropertyGridEx control onto your form, decorate your object with a few additional attributes, and you’re set. Using the PropertyGridEx is just about as painless as a run-of-the-mill PropertyGrid.
If for some reason you are unable to change a PropertyGrid out, you can use the ShinyDesign.Design.TypeDescriptorSurrogate class. It gives you *almost* all of the benefits of the PropertyGridEx class – the key difference being that multiple property tabs are not available in this situation. You wrap the object being inspected in a new instance of TypeDescriptorSurrogate, and assign the surrogate object as the SelectedObject of the property grid. The actual object is updated, just as if you were working with the PropertyGridEx.
If you plan on using this in applications, I’d appreciate a nod, or at least an e-mail letting me know that you’re using it and whether you found it helpful. The license terms stipulate that my copyright notice must appear in source code redistributions, but not in binary redistributions, with the exception of the disclaimer of warranties (which must be included in all forms in some way). Also, if you come across a bug, please drop me an e-mail so I can roll the fix into the main source tree.
Now that it’s out, I’m not sure how much extra time I’ll be putting into it, but I know that there are some updates I’d like to make to it, including the ability to inspect fields, methods, and events. If possible, I’d like the ability to as closely mirror Hawkeye as possible, except that I don’t really care to write the code to inject into other processes. (This is where the multiple-property-tab idea came from in the first place). But at the end of the day, I see the most use in this coming out of people who want to use it for their user configuration screens – that’s why I built it in the first place.