如何取消选中gridControl的侧面datatemplate中的所有复选框按钮点击在WPF使用C#? [英] How to uncheck all CheckBox in side datatemplate of gridcontrol on button click in WPF using C#?

查看:263
本文介绍了如何取消选中gridControl的侧面datatemplate中的所有复选框按钮点击在WPF使用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GridControl列中有一个复选框。 执行某些操作后,GridControl内的所选复选框必须在WPF按钮点击时未复选框。任何想法?

I have a CheckBox in GridControl Column. After performing some operation the selected checkboxes inside GridControl must be UNCHECKED on button click in WPF. Any idea?

<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" />

帮助欣赏!

推荐答案

在我看来,其中一个解决方案可以通过这个:

In my opinion, one of the solutions can pass by this:


  1. 在数据报上有一个属性绑定到复选框上的isselected属性;

  2. 在按钮单击时,在CommandParameter中传递gridview itemsource,或者如果将itemssource绑定到使用该列表的数据文件中的列表。做一个foreach,把属性IsSelected(我在1中说)为false ...复选框中的绑定必须是双向的,并实现InotifyPropertyChanged。

如果我不清楚,请告诉我:)

If I was not clear in any point, please just tell me :)

回答:

EDIT ----------------------------

这是我使用默认控件的示例(我没有devexpress)。

This is my example working with the default controls (I don't have 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上:

On the 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的实现:

And I have this class with the implementation of 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;
        }


    }
}

只要分析一下,尝试了解并适应您的代码。

Just analyse this and try to understand and adapt to your code.

注意,

这篇关于如何取消选中gridControl的侧面datatemplate中的所有复选框按钮点击在WPF使用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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