又番的自留地

偷菜不如偷师

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

要求:DataGrid的CheckBox列单击任CheckBox可以绑定到后台Command,并且单击就能改变
(默认的DataGridCheckBoxColumn需要单击二次,才有勾选,否选效果)

在尝试了自定义CellEditTemplate,DataGridCheckBoxColumn之后选择下面的方法

1,问题Mode=TwoWay,在CellTemplate不起做用 ,所以在后台Command,要赋值,才能达到最终效果

<DataGridTemplateColumn CanUserSort="False" HeaderStyle="{DynamicResource chkAll}" >
  <DataGridTemplateColumn.CellTemplate>
  <DataTemplate>
    <CheckBox IsChecked="{Binding IsSelect, Mode=OneWay}"
          Command="{Binding DataContext.SingleJobSelectCommand,
            RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
          CommandParameter="{Binding}"
          HorizontalAlignment="Center" VerticalAlignment="Center" >
    </CheckBox>
  </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

posted on 2013-12-05 17:11  Kyle.cj  阅读(1659)  评论(2)    收藏  举报