Microsoft updates Forms PropertyGrid to support dark theme in VS2012

The System.Windows.Forms.PropertyGrid is a superb control, IMHO the best and most versatile control I've ever seen. It's over 10 years old and still rocks. The PropertyGrid is used extensively in Visual Studio for as long as I can remember and rightfully so. I enjoy working with it on a daily basis. With Visual Studio 2012, Microsoft introduces the great looking dark theme and guess what, they finally updated the PropertyGrid in order to cope with the new color requirements. The property grid is old and does have some issues as can be seen here, here and here. Some of these issues are now addressed in the new PropertyGrid.

This is great, however history repeats itself once again. When Microsoft decided to start using WPF for VisualStudio 2010, they suddenly fixed a whole lot of issues including the crappy text rendering. Improvements in existing frameworks are not initiated because Microsoft listens to the dev community, but only because they need the fix themselves. At least, that is my perception. And now it's happening again with the good old property grid.

Microsoft decided to fix some PropertyGrid limitations by adding the following new properties (almost all color related);

  • CanShowVisualStyleGlyphs
  • CategorySplitterColor
  • CommandsBorderColor
  • DisabledItemForeColor
  • HelpBorderColor
  • SelectedItemWithFocusBackColor
  • SelectedItemWithFocusForeColor
  • ViewBorderColor

This is awesome news for all devs using the PropertyGrid in their apps (as I do with Silverlight Spy and XAML Spy). The new properties are available when you build .NET 4.5 desktop apps in Visual Studio 2012. But even if you are still bound to .NET 4.0 and Visual Studio 2010 you can use the new properties.

I've been doing some research and here's what I found; the .NET Framework v4 assemblies referenced in your project are located in [ProgramFiles]ReferenceAssemblies. The actual assemblies loaded at runtime originate from the GAC folder in [Windows]Microsoft.NETassembly. And here's the crux, the ReferenceAssemblies differ from the GAC assemblies. The System.Windows.Forms assembly in the GAC contains the new PropertyGrid, where the ReferenceAssembly does not. So the new property grid is available at runtime to .NET 4 apps. This is true only when the .NET 4.5 framework has been installed (remember, NET 4.5 does an in-place upgrade of .NET 4)

So how do you use the new PropertyGrid properties at runtime? Well, assign the propertygrid to a dynamic variable and get/set the properties in a late-bound fashion.

This won't compile;

var grid = new PropertyGrid();
grid.SelectedItemWithFocusBackColor = myForeColor;

But this works fine (no intellisense though)

dynamic grid = new PropertyGrid();
grid.SelectedItemWithFocusBackColor = myForeColor;

So in short; the PropertyGrid has been updated in .NET 4.5, most likely because Microsoft needed it for VS2012. The good news is that the updated property grid can also be used in .NET 4.0 apps.

Enjoy

Published: August 7, 2012

2 Comments

  1. Edward Piccoli said: says:

    Thanks, does this grid work in LightSwitch. I sure would like a little more power like grouping and totaling and especially darken a little the washed out blue of LightSwitch (maybe just a shade darker). Also, when will be your next release of Document Viewer, just curious.

    Best Regards,

    Edward Piccoli

  2. Koen said: says:

    The propertygrid only works in .NET forms and WPF apps. It's not available to Silverlight (where LightSwitch is running on)

 

Leave a comment

Comments are closed for this post