C#code在WPF数据网格中选择所有复选框 [英] c# code for select all checkbox in wpf datagrid
本文介绍了C#code在WPF数据网格中选择所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些C#code选择/取消选择所有复选框在WPF 3.5框架数据网格。 我想通过单击电网单标题复选框做到这一点。
I need some c# code to select / deselect all checkboxes in a datagrid in WPF 3.5 framework. I would like to do this by clicking a single header checkbox in the grid.
请帮忙。
推荐答案
这可以声明进行。下面创建的每一行,并可以切换行选择的一个复选框列。复选框列的标题可点击做一个选择的所有行。
This can be done declaratively. The following creates a checkbox column for each row and which can toggle row selections. The header of the checkbox column can be clicked to do a select all of the rows.
从XAML的相关部分
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit">
<toolkit:DataGrid Name="dataGrid"
ItemsSource="{Binding}" AutoGenerateColumns="True"
SelectionMode="Extended" CanResizeRows="False">
<toolkit:DataGrid.RowHeaderTemplate>
<DataTemplate>
<Grid>
<CheckBox IsChecked="{
Binding Path=IsSelected,
Mode=TwoWay,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type toolkit:DataGridRow}}}"
/>
</Grid>
</DataTemplate>
</toolkit:DataGrid.RowHeaderTemplate>
</toolkit:DataGrid>
</Window>
这篇关于C#code在WPF数据网格中选择所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文