views:

534

answers:

2

Hi. 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...

Any help would be appreciated.

/J

+1  A: 

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

Timores
Nope doesn't work. Read this about UpdateSourceTrigger on Vincent Sibals blog...2. DataGridColumn.Binding will automatically coerce the binding to BindingMode.TwoWay and UpdateSourceTrigger.ExplicitNo matter how you declare the binding for DataGridColumn.Binding, internally it will coerce the BindingMode to TwoWay and UpdateSourceTrigger to Explicit (even if you set them explicitly yourself).
Johan Zell
This worked for me. Thanks.
alimbada
+1  A: 

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
No, 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.
macias