I am using property grid in a WPF project to display UI items. So basically, for properties of collection type, a comboBox is required. For this purpose I am using Extended PropertyValueEditor. The problem is that for each collection [say Languages or Operating Systems or any other collection...] I have to create a separate comboBox editor as ItemsSource is different for each. Is there any way out to create a generic comboBox and to set its ItemsSource property depending upon the collection type. (Say that a set of specific functions are there which are returning collection of languages or Operating Systems )
PS:I have a humongous number of collections to display. Any other approach too will be appreciated !!!
Please find below the sample code :
This is the editor for Operating Systems collection
public class OperatingSystemsEditor : ExtendedPropertyValueEditor
{
public OperatingSystemsEditor()
{
DataTemplate customTemplate = new DataTemplate();
FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof (ComboBox));
LanguageParser utilObj = new LanguageParser();
comboBox.SetValue(ComboBox.ItemsSourceProperty, utilObj.GetOperatingSystemsAll());
Binding selectedItem = new Binding("Value");
comboBox.SetValue(ComboBox.SelectedItemProperty, selectedItem);
selectedItem.Mode = BindingMode.TwoWay;
this.InlineEditorTemplate = customTemplate;
this.InlineEditorTemplate.VisualTree = comboBox;
}
}
This is the editor for Languages collection
public class LanguagesEditor : ExtendedPropertyValueEditor
{
public LanguagesEditor()
{
DataTemplate customTemplate = new DataTemplate();
FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));
LanguageParser utilObj = new LanguageParser();
comboBox.SetValue(ComboBox.ItemsSourceProperty, utilObj.GetLanguagesAll());
Binding selectedItems = new Binding("Value");
comboBox.SetValue(ComboBox.SelectedItemProperty, selectedItems);
selectedItems.Mode = BindingMode.TwoWay;
this.InlineEditorTemplate = customTemplate;
this.InlineEditorTemplate.VisualTree = comboBox;
}
}
How I am making use of these editors :
[Editor(typeof(LanguagesEditor), typeof(ExtendedPropertyValueEditor))]
public ObservableCollection<>Languages
{get; set;}
[Editor(typeof(OperatingSystemsEditor), typeof(ExtendedPropertyValueEditor))]
public ObservableCollection<> OperatingSystems
{get; set;}