artos
artos

Reputation: 751

SelectedItem is null in DataGridTemplateColumn with ComboBox

I have a Datagrid and DataGridTemplateColumn which is ComboBox

<DataTemplate x:Key="ComboBoxPackagingType">
  <ComboBox SelectedItem="{Binding   PackagingType.SelectedItem, Mode=TwoWay}" ItemsSource="{Binding PackagingType.ItemsSource}"/>
</DataTemplate>

...

<DataGridTemplateColumn CellTemplate="{StaticResource ComboBoxPackagingType}"/>

The SelectedItem is never changing the value after selecting an Item from list. I set the breakpoints on both get and set functions and it is stopping on get function after changing the ItemSource of my DataGrid but never on the set function after selecting an Item from list.

Why?

Upvotes: 2

Views: 747

Answers (1)

bryan
bryan

Reputation: 190

Try adding UpdateSourceTrigger=PropertyChanged to the binding of your ComboBox's selected item like so:

<DataTemplate x:Key="ComboBoxPackagingType">
  <ComboBox SelectedItem="{Binding PackagingType.SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding PackagingType.ItemsSource}"/>
</DataTemplate>

This worked for me.

Upvotes: 1

Related Questions