DataGridCheckBoxColumn immediate binding
Solution 1
You have to set the UpdateSourceTrigger property of the Binding to PropertyChanged. The default is LostFocus.
Solution 2
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
Johan Zell
Updated on June 07, 2022Comments
-
Johan Zell almost 2 years
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.
-
greenoldman almost 14 yearsNo, it does not default to it. You have to set it manually, i.e. "UpdateSourceTrigger=PropertyChanged". Otherwise you will make changes only visually (VS2010). Anyway, BIG THANK YOU for the help.
-
Will Dean over 13 yearsThis worked for me (WPF4) too - perhaps this was something that changed for .NET4
-
aruno over 12 yearsnote: you need to do UpdateSourceTrigger even for a textbox inside a DataGrid. probably want PropertyChanged=LostFocus in this case (even though this is the default)
-
Richard almost 12 yearsNot for me it doesn't. (WPF4)
-
Aducci about 10 yearsI had to do this when using Silverlight 5