This project has moved. For the latest updates, please go here.

PropertyGrid Combobox Custom Editor

Mar 22, 2013 at 12:56 PM
Edited Mar 22, 2013 at 12:58 PM
Hi there,

I'm trying to get a combo box to display a drop down list of items for a particular property (an enumeration), but everything I've tried results in an empty list.

The object property itself can't have any UI attributes associated with it (it's in a separate lib), so I'm trying to do everything in the xaml/c# code for the window displaying the property grid.

I've tried setting the item source of the combo box a number of different ways :
                     <xctk:EditorDefinition>
                        <xctk:EditorDefinition.PropertiesDefinitions>
                            <xctk:PropertyDefinition Name="BlendState" />
                        </xctk:EditorDefinition.PropertiesDefinitions>
                        <xctk:EditorDefinition.EditorTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding Path=BlendOptions}" />
                            </DataTemplate>
                        </xctk:EditorDefinition.EditorTemplate>
                    </xctk:EditorDefinition>
Where BlendOptions has been an IItemSource instance, a List<string> instance etc belonging to the class with the property grid instance... but nothing I'm doing seems to work. I'm definitely populating the lists/item sources before the components for the window are initialized.

I've also tried using a dictionary, setting the DisplayMemberPath & SelectedValuePath, but I still get an empty combo box.

The funny thing is if I make a combo box outside of the editor definition (embed it in to the UI), the bindings seem to work.

Any ideas?
Mar 22, 2013 at 2:39 PM
The DataContext of the template instance will be the "PropertyItem" representing the property.
To access the underlying selected object. Pass thru the "Instance" property.

So this may be working:
 <ComboBox ItemsSource="{Binding Path=Instance.BlendOptions}" />
Mar 22, 2013 at 3:17 PM
Thanks for the quick reply.

I update the ComboBox as you suggested and moved the list to my custom type descriptor... that worked like a charm!

Is there any way to set the DataContext of the property grid to the control that's housing the it? It's not a big issue, I just don't want to balloon out my type descriptor with dictionaries for every enum it may encounter.

Cheers!
Mar 22, 2013 at 3:21 PM
Actually I guess it doesn't make any sense to modify the data context for the property grid's custom editor. Forget I said anything :)
Mar 22, 2013 at 6:37 PM
This may be working (eg. getting the DataContext of the PropertyItem (the actual DataContext)
<ComboBox ItemsSource="{Binding Path=DataContext.BlendOptions}" />