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:
<UserControl>
<UserControl.Resources>
<local:PropertyEditorSelector x:Key="propertyEditorSelector" />
</UserControl.Resources>
<PropertyGrid SelectedObjects="{Binding Path=MyCollection}"
IsItemDefaultContextMenuEnabled="False"
ItemTemplateSelector="{StaticResource propertyEditorSelector}">
<PropertyGrid.DataFactory><local:MyDataFactory/></PropertyGrid.DataFactory>
<PropertyGrid>
</UserControl>
//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?
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:
<UserControl>
<UserControl.Resources>
<local:PropertyEditorSelector x:Key="propertyEditorSelector" />
</UserControl.Resources>
<PropertyGrid SelectedObjects="{Binding Path=MyCollection}"
IsItemDefaultContextMenuEnabled="False"
ItemTemplateSelector="{StaticResource propertyEditorSelector}">
<PropertyGrid.DataFactory><local:MyDataFactory/></PropertyGrid.DataFactory>
<PropertyGrid>
</UserControl>
//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?