I have and DataGridComboBoxColumn in the DataGrid a WPF window. I am assigning DataContext to Window as below:
cls = new MyClass
{
selValue = 2,
DataGrid = dtGrid,
ComboGrid = dtCombo
};
this.DataContext = cls;
Following is the XAML for DataGridComboBoxColumn:
<DataGridComboBoxColumn Header="Item Name" SelectedValueBinding="{Binding Path=Item_Id}" SelectedValuePath="ItemId" DisplayMemberPath="ItemName">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<!-- modified this code as per suggestion ///-->
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ComboGrid }" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ComboGrid }" />
</Style>
</DataGridComboBoxColu
mn.EditingElementStyle>
Still Combobox in grid showing blank. No data is being listed in Combobox. Then, I wrote following code in Windows codebehind, it start working.
((DataGridComboBoxColumn)this.testGrid.Columns[1]).ItemsSource = cls.ComboGrid.DefaultView;
Is there anyway to handle this case in XMAL itself using MVVM? I am reluctant to use this apporache.