Home » Blog

rounded header

Switching to WPF Property Grid 2.0

WPF Property Grid 2.0 is highly compatible with 1.0, but there are a couple of changes which may affect a small amount of existing code.

First, if you’re using BuiltInEditorStyles to customise the appearance of the built-in editors, you’ll now need to wrap the declarations in a BuiltInEditorStyleCollection. That is, you’ll need to change this:

<ms:PropertyGrid.BuiltInEditorStyles>
  <!-- ... style declarations ... -->
</ms:PropertyGrid.BuiltInEditorStyles>

to this:

<ms:PropertyGrid.BuiltInEditorStyles>
  <ms:BuiltInEditorStyleCollection>
    <!-- ... style declarations ... -->
  </ms:BuiltInEditorStyleCollection>
</ms:PropertyGrid.BuiltInEditorStyles>

This has been in nightly builds for a while so you may already have made this change; if so, you won’t need to do anything more.

The reason for this change was to allow the BuiltInEditorStyles property to be set via a style itself. The benefit of this is that if you are styling the grid to give it a custom appearance, you can package up your styling of the built-in editors as part of that style.

Second, we have changed the way that highlighting the tree/list item for the editor cell with focus works. If you have a custom style for your grid rows, you may now find that, when the user clicks into a property to edit it, the corresponding row no longer gets highlighted. The solution for this is to databind the IsSelected property of your item control (ListBoxItem, TreeViewListItem, etc.). You will need to use a MultiBinding similar to the following:

<MultiBinding Converter="{StaticResource AreEqual}">
  <MultiBinding.Bindings>
    <Binding Path="Header" RelativeSource="{RelativeSource Self}" />
    <Binding Path="SelectedGridItem" RelativeSource="{RelativeSource AncestorType={x:Type ms:PropertyGrid}}" />
  </MultiBinding.Bindings>
</MultiBinding>

where AreEqual is an instance of the AreEqualConverter included in the grid assembly.

If you need any further assistance making these changes, let us know in the forums and we’ll be glad to help!

Leave a Reply

Data Products Visual Controls Community Store
LightSpeed ORM
NHibernate Designer
SimpleDB Tools
SharePoint Tools
WPF Elements
WPF Diagrams
Silverlight Elements
Forums
Blog
Register
Login
Subscribe to newsletter
Buy Now
My Account
Volume Discounts
Purchase Orders
Contact Us