10
votes

I'm using the WPF Toolkit Datagrid and have one column which is a DataGridCheckBoxColumn bound to a bool property on my ViewModel.

My problem is that I wan't the property to get it's value updated immediately when the user checks or unchecks the checkbox.

Now you have to navigate away from the cell in order to have the property updated. It's a checkbox. It can't be in the middle of editing like a textbox can.

3

3 Answers

25
votes

You have to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.

9
votes

The solution is to NOT use the DataGridCheckBoxColumn for this. Instead use

<dg:DataGridTemplateColumn Width="20" Header="" SortMemberPath="IsSelected">
   <dg:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <CheckBox  IsChecked="{Binding Path=IsSelected}" />
       </DataTemplate>
   </dg:DataGridTemplateColumn.CellTemplate>
 </dg:DataGridTemplateColumn>

which defaults to having its UpdateSourcerigger to PropertyChanged...

DataGridCheckBoxColumn has it's UpdateSourceTrigger set to Explicit and it cannot be changed. Read more here: http://blogs.msdn.com/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx