如何使用C#在WPF中单击按钮时取消选中gridcontrol的side datatemplate中的所有复选框?
我在GridControl列中有一个复选框执行某些操作后,必须在WPF中单击按钮时取消选中GridControl中的选中复选框。有什么想法吗如何使用C#在WPF中单击按钮时取消选中gridcontrol的side datatemplate中的所有复选框?,c#,wpf,checkbox,grid,devexpress,C#,Wpf,Checkbox,Grid,Devexpress,我在GridControl列中有一个复选框执行某些操作后,必须在WPF中单击按钮时取消选中GridControl中的选中复选框。有什么想法吗 <dxg:GridControl Name="grdInfill" Height="700" VerticalAlignment="Center"> <dxg:GridControl.Columns> <dxg:GridColumn AllowEditing="True">
<dxg:GridControl Name="grdInfill" Height="700" VerticalAlignment="Center">
<dxg:GridControl.Columns>
<dxg:GridColumn AllowEditing="True">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
CheckBox Name="chkSelect" HorizontalAlignment="Center" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected,Mode=TwoWay}" Checked="CheckEdit_Checked" Unchecked="CheckEdit_Unchecked"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name="grdInfillInner" ShowTotalSummary="True" AutoWidth="True"
DetailHeaderContent="True" ShowIndicator="False" ShowGroupPanel="False"
CellValueChanging="grdInfillInner_CellValueChanging">
<!--GroupRowTemplate="{StaticResource descriptionHeader}"-->
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
<Button Name="BtnClearAllCheckbox" Content="Clear All Checkbox" Height="20" Width="80" />
复选框Name=“chkSelect”HorizontalAlignment=“Center”IsChecked=“{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsSelected,Mode=TwoWay}”Checked=“CheckEdit\u Checked”Checked=“CheckEdit\u Unchecked”/
谢谢你的帮助 在我看来,其中一个解决方案可以忽略这一点:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="checkBoxTemplate">
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"></CheckBox>
</DataTemplate>
</Window.Resources>
<Grid>
<StackPanel>
<ListView ItemsSource="{Binding listExample}">
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource checkBoxTemplate}"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Test1}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Button Content="Uncheck all" Click="Button_Click"></Button>
</StackPanel>
</Grid>
</Window>
在代码背后:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public List<Example> listExample { get; set; }
public MainWindow()
{
InitializeComponent();
this.listExample = new List<Example>();
listExample.Add(new Example { IsChecked = false, Test1 = "teste" });
listExample.Add(new Example {IsChecked = false, Test1 = "TTTTT!" });
DataContext = this;
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.listExample.ForEach(x => x.IsChecked = false);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间WpfApplication1
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共列表列表示例{get;set;}
公共主窗口()
{
初始化组件();
this.listExample=新列表();
Add(新示例{IsChecked=false,Test1=“teste”});
Add(新示例{IsChecked=false,Test1=“TTTTT!”);
DataContext=this;
}
已选中私有无效复选框(对象发送方、路由目标方)
{
}
私有无效复选框\u未选中(对象发送方,路由目标)
{
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
this.listExample.ForEach(x=>x.IsChecked=false);
}
}
}
我用INotifyPropertyChanged实现了这个类:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication1
{
public class Example : INotifyPropertyChanged
{
private bool isChecked;
public bool IsChecked { get { return isChecked; } set { SetField(ref isChecked, value, "IsChecked"); } }
public string Test1 { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetField<T>(ref T field, T value, string propertyName)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间WpfApplication1
{
公共类示例:INotifyPropertyChanged
{
私人住宅被检查;
public bool IsChecked{get{return IsChecked;}set{SetField(ref IsChecked,value,“IsChecked”);}
公共字符串Test1{get;set;}
公共事件属性更改事件处理程序属性更改;
受保护的虚拟void OnPropertyChanged(字符串propertyName)
{
PropertyChangedEventHandler处理程序=PropertyChanged;
if(handler!=null)handler(这是新的PropertyChangedEventArgs(propertyName));
}
受保护的布尔设置字段(参考T字段、T值、字符串属性名称)
{
if(EqualityComparer.Default.Equals(字段,值))返回false;
字段=值;
OnPropertyChanged(propertyName);
返回true;
}
}
}
只需分析这一点,并尝试理解和适应您的代码
关于,Duplicate-IsSelected是我绑定的布尔属性字段。我是wpf的新手,所以请您提供上面的样品好吗?我将尝试做一个快速的例子。:)给我几分钟;)谢谢你抽出时间!我真的很感激你的工作!通过分析您的代码片段,我在一定程度上修改了代码!而且做得很好。。。!非常感谢!:)