我在GridControl列中有一个CheckBox。 执行某些操作后,GridControl中的选定复选框必须在WPF按钮单击时取消选中。有什么想法吗?
<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" />
帮助感谢!
答案 0 :(得分:3)
在我看来,其中一个解决方案可以通过:
如果我不清楚,请告诉我:)
此致
编辑----------------------------
这是我使用默认控件的示例(我没有devexpress)。
在XAML上:
<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>
关于CodeBehind:
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);
}
}
}
我有这个类实现了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;
}
}
}
只需分析一下,然后尝试理解并适应您的代码。
此致