1

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;}
almulo
  • 4,918
  • 1
  • 20
  • 29
  • i am a newbie to stackoverflow. so if this is not the proper structure to ask the question , please let me know and why this downvote? – pratik kumar Jun 03 '15 at 15:54
  • It would be easier to help you if you shared the relevant code, or a similar example. If I understand correctly, you want the ComboBoxes of your application to have some generic way of knowing their correct ItemsSource (and SelectedItem, I guess)? – almulo Jun 03 '15 at 15:56
  • Updated the relevant code.....Thanks in advance for support !!! – pratik kumar Jun 03 '15 at 17:07
  • Ok, judging by your code I'm gonna assume you're talking about a Windows Workflow Foundation project, not a simple Windows WPF application... I'm afraid I have no idea of WWF, so I'm tagging your question with the `workflow-foundation` tag to see if it gets attention from the right people. – almulo Jun 04 '15 at 09:41
  • I have run into a similar problem. In my case I have set the Collection (which is the ItemSource for combobox) to be represented by my custom editor. Now my combobox is being populated correctly, but doing it this way means that I have no way to intercept which item in the combo box is being selected. Were you able to find a solution for this? – Karthik Balasubramanian Jun 12 '15 at 18:42
  • The codes in your question helped me. Thanks! – electron Dec 27 '17 at 20:12

0 Answers0