From 396270e3c4787c4ed4bd841a566efc9718f32a15 Mon Sep 17 00:00:00 2001 From: Waheed Ahmad Date: Wed, 11 Dec 2024 01:37:43 +0500 Subject: [PATCH] fixed select all check box fast click issue --- src/WinUI.TableView/TableViewColumnHeader.cs | 16 +++++++------- src/WinUI.TableView/TableViewHeaderRow.cs | 22 ++++++++----------- .../Themes/TableViewColumnHeader.xaml | 1 - .../Themes/TableViewHeaderRow.xaml | 1 - 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/WinUI.TableView/TableViewColumnHeader.cs b/src/WinUI.TableView/TableViewColumnHeader.cs index a3cc1b2..21b16bb 100644 --- a/src/WinUI.TableView/TableViewColumnHeader.cs +++ b/src/WinUI.TableView/TableViewColumnHeader.cs @@ -189,7 +189,8 @@ protected override void OnApplyTemplate() if (_selectAllCheckBox is not null) { - _selectAllCheckBox.Tapped += OnSelectAllCheckBox_Tapped; + _selectAllCheckBox.Checked += OnSelectAllCheckBoxChecked; + _selectAllCheckBox.Unchecked += OnSelectAllCheckBoxUnchecked; } if (menuItem?.FindDescendant(x => x.Name == "SearchBox") is { } searchBox) @@ -212,16 +213,15 @@ private void OnSearchBoxKeyDown(object sender, KeyRoutedEventArgs e) } } - private async void OnSelectAllCheckBox_Tapped(object sender, TappedRoutedEventArgs e) + private void OnSelectAllCheckBoxChecked(object sender, RoutedEventArgs e) { var checkBox = (CheckBox)sender; + _optionsFlyoutViewModel.SetFilterItemsState(checkBox.IsChecked == true); + } - if (checkBox.IsChecked is null) - { - await Task.Delay(5); - checkBox.IsChecked = false; - } - + private void OnSelectAllCheckBoxUnchecked(object sender, RoutedEventArgs e) + { + var checkBox = (CheckBox)sender; _optionsFlyoutViewModel.SetFilterItemsState(checkBox.IsChecked == true); } diff --git a/src/WinUI.TableView/TableViewHeaderRow.cs b/src/WinUI.TableView/TableViewHeaderRow.cs index 918f57e..6cf0c43 100644 --- a/src/WinUI.TableView/TableViewHeaderRow.cs +++ b/src/WinUI.TableView/TableViewHeaderRow.cs @@ -65,7 +65,8 @@ protected override void OnApplyTemplate() if (_selectAllCheckBox is not null) { - _selectAllCheckBox.Tapped += OnSelectAllCheckBoxTapped; + _selectAllCheckBox.Checked += OnSelectAllCheckBoxChecked; + _selectAllCheckBox.Unchecked += OnSelectAllCheckBoxUnchecked; } if (TableView.Columns is not null && GetTemplateChild("HeadersStackPanel") is StackPanel stackPanel) @@ -271,7 +272,7 @@ internal void CalculateHeaderWidths() DispatcherQueue.TryEnqueue(() => header.Measure( - new Size(header.Width, + new Size(header.Width, _headersStackPanel?.ActualHeight ?? TableView.HeaderRowHeight))); } } @@ -343,19 +344,14 @@ private void SetSelectAllButtonState() } } - private void OnSelectAllCheckBoxTapped(object sender, RoutedEventArgs e) + private void OnSelectAllCheckBoxChecked(object sender, RoutedEventArgs e) { - var checkBox = (CheckBox)sender; + TableView?.SelectAllSafe(); + } - if (checkBox.IsChecked == true) - { - TableView?.SelectAllSafe(); - } - else - { - checkBox.IsChecked = false; - TableView?.DeselectAll(); - } + private void OnSelectAllCheckBoxUnchecked(object sender, RoutedEventArgs e) + { + TableView?.DeselectAll(); } internal void EnsureGridLines() diff --git a/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml b/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml index 4ca3141..81529d8 100644 --- a/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml +++ b/src/WinUI.TableView/Themes/TableViewColumnHeader.xaml @@ -164,7 +164,6 @@ BorderBrush="{ThemeResource MenuFlyoutSeparatorBackground}">