Hello,
Inside a UserControl I would like to populate a XamComboEditor using ComboBoxItemsProvider (the ComboBox is in a grid), according to the current context.
The context is defined through an ObjectDataProvider in the parent UserControl.The problem is that the ComboEditor remains empty as I'm not defining explicitely the source for the binding.Of course I tested with a simple XamComboEditor outside the grid and without using ComboBoxItemsProvider, it's working perfectly.
Here's my code to define the style (it's inside the resources of the XamDataGrid) :
<Style x:Key="ModuleFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Path=Modules}" DisplayMemberPath="lblModule"/> </Setter.Value> </Setter></Style>
Thanks for your help
Thanks, it's working perfectly.
Part of the problem is that the ComboBoxItemsProvider does not have access to the datacontext of the combobox (since that would require an inheritance context and that is internal to wpf currently as well as available to certain types like freezable which really isn't an appropriate base class for comboboxitemsprovider). One option would be to instead set the ItemsSource property of the XamComboEditor since the control has access to its data context. However you still cannot set the binding path you have since the datacontext for the editor element in the cell will be the containing record (since itemscontrol type controls change the datacontext to be that of the item that it represents). Even if you were to go down this path this wouldn't be the most effecient way since every editor instance would be creating its own copy of the items which defeats the major benefit of using the XamComboEditor/ComboBoxItemsProvider (this would actually happen if your snippet worked as well since each editor would have an instance of the items provider). Probably the best solution is to put an instance of the ComboBoxItemsProvider into the resources of the xamDataGrid and use something like Josh's DataContextSpy as the source when binding the ItemsSource of the ComboBoxItemsProvider. e.g.