如何在 WPF DataGrid 中执行单击复选框选择? [英] How to perform Single click checkbox selection in WPF DataGrid?

查看:32
本文介绍了如何在 WPF DataGrid 中执行单击复选框选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataGrid,第一列作为文本列,第二列作为 CheckBox 列.我想要的是,如果我单击复选框.应该检查一下.

但是,需要单击两次才能被选中,第一次单击单元格被选中,第二次单击复选框被选中.如何使复选框通过单击被选中/取消选中.

I have a DataGrid with first column as text column and second column as CheckBox column. What I want is, if I click the check box. It should get checked.

But, it takes two click to get selected, for first click the cell is getting selected, for the second clicks the check box is getting checked. How to make the check box to get checked/unchecked with a single click.

我使用的是 WPF 4.0.DataGrid 中的列是自动生成的.

I'm using WPF 4.0. Columns in the DataGrid are AutoGenerated.

推荐答案

对于单击 DataGrid 复选框,您可以将常规复选框控件放在 DataGridTemplateColumn 中并设置 UpdateSourceTrigger=PropertyChanged.

For single click DataGrid checkbox you can just put regular checkbox control inside DataGridTemplateColumn and set UpdateSourceTrigger=PropertyChanged.

<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <CheckBox IsChecked="{Binding Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" />
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

这篇关于如何在 WPF DataGrid 中执行单击复选框选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆