WPF DataGrid: DataGridComboBoxColumn.ItemsSource Binding problems


We had some problem using the ItemsSource Property of the DataGridComboBoxColumn. Binding it to an ObservableCollection did not work and resulted in this error:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ControlFlow.Value.RequestsFlat.Value; DataItem=null; target element is 'DataGridComboBoxColumn' (HashCode=8873934); target property is 'ItemsSource' (type 'IEnumerable')
We are not sure why this error happened. One idea is that there is some problem with the binding of the ItemsSource, and the fact, that the DataGridComboBoxColumn has no DataContext property. Perhaps somebody can verfiy this?
To solve our problem, we created a new property ItemsSourceBinding of type BindingBase. This works similar to the SelectedItemBinding property, that already exsists and we use the ApplyBinding method to set the ItemsSourceProperty of the combobox. In our first tests this worked fine. Is this the correct way to solve this problem? Or is there also some other way?
You find attached the DataGridComboBoxColumn.cs with our changes.
This is some extract from our xaml:
<controls:DataGridComboBoxColumn Header="Receive at"
                        SelectedValueBinding="{Binding Path=Test.Value}"
                        ItemsSourceBinding="{Binding Path=MyObservableCollection}">

file attachments

Closed Feb 19, 2009 at 12:39 AM by BenCarter


nesher wrote Dec 18, 2008 at 11:28 AM

I'm having same problem. But I think the Impact is High!

vinsibal wrote Jan 6, 2009 at 12:54 PM

chnicola wrote Feb 13, 2009 at 11:27 PM

I have used the workaround, but I agree that there should be a cleaner solution. It should be possible to bind ItemsSource to the current datacontext of the DataGrid. Nonetheless the workaround is sufficient so I am not sure it is worth saying the ipact is high.

wrote Feb 19, 2009 at 12:39 AM

wrote Feb 22, 2013 at 1:41 AM

wrote May 16, 2013 at 12:31 PM