How to use the ValueTemplateSelector in propertygrid

Grids for WPF Forum

Posted 13 years ago by Moondance
Version: 11.1.0545
I have a property grid that binds to a dynamic collection through the SelectedObjects property (I do not know what type of data I will get, every item can be of a different type, string boolean etc). I also have my own DataFactory which processes correctly all the items in the collection. Everything works fine and displays correctly with a texbox.
But now, according to the type of data I get, I want to use different datatemplates/editors.
I though of using a ValueTemplateSelector for that but I am not sure how to go about it.
Mimicking what I would do with a DatatemplateSelector, here is what I have so far:

<local:PropertyEditorSelector x:Key="propertyEditorSelector" />

<PropertyGrid SelectedObjects="{Binding Path=MyCollection}"
ItemTemplateSelector="{StaticResource propertyEditorSelector}">

//code behind
public class PropertyEditorSelector : ValueTemplateSelector
public override DataTemplate SelectTemplate(object item, DependencyObject container)
var temp = string.Empty; //check for type here and act accordingly
return null;

public PropertyEditorSelector(PropertyGrid grid) : base(grid)

The problem is that the ValueTemplateSelector does not have an empty constructor like the DataTemplateSelector so my xaml code does not even compile.

Can someone help out?

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA

If you want to derive from our ValueTemplateSelector class, then you'd need to duplicate it's constructor (which must be passed the owning PropertyGrid). You'd then have to assign the PropertyGrid.ValueTemplateSelector property in code-behind. Our ValueTemplateSelector queries the property editors defined in BuiltinEditors, as well as on the PropertyGrid and the associated property. It also uses the PropertyGrid instance to resolve any DataTemplates using FindResource.

Alternatively, you can derive your selector directly from DataTemplateSelector, if you'd like to completely replace our editor lookup logic.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.