开发者

DataGridCheckBoxColumn immediate binding

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开发者_Python百科. It can't be in the middle of editing like a textbox can.


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


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


Another approach:

http://wpf.codeplex.com/wikipage?title=Single-Click%20Editing&ProjectName=wpf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜