From de00cbf20abf5178e27c8d4147d153602708e76f Mon Sep 17 00:00:00 2001 From: Guilherme <57814418+DevLGuilherme@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:32:09 -0300 Subject: [PATCH] [CmdPal] Fix filters visibility on non-ListPage (#42828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of the Pull Request This PR aims to fix the issue where filters from a ListPage remain visible when navigating to other pages. ## PR Checklist - [x] Closes: #42827 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ### Before: ![FiltersIssue](https://github.com/user-attachments/assets/b0ad6059-9a11-4e12-821d-7202358e25bb) ### After: ![FiltersFix](https://github.com/user-attachments/assets/b9ee71ee-cb5d-4ef9-b9fc-bc2e2a710b5c) ## Validation Steps Performed --------- Co-authored-by: Jiří Polášek --- .../ListViewModel.cs | 21 ++++- .../PageViewModel.cs | 2 + .../Controls/FiltersDropDown.xaml | 2 +- .../AllIssueSamplesIndexPage.cs | 29 +++++++ ...ibleAfterSwitchingFromListToContentPage.cs | 76 +++++++++++++++++++ .../SamplePagesExtension/SamplesListPage.cs | 6 ++ 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 src/modules/cmdpal/ext/SamplePagesExtension/Pages/IssueSpecificPages/AllIssueSamplesIndexPage.cs create mode 100644 src/modules/cmdpal/ext/SamplePagesExtension/Pages/IssueSpecificPages/SamplePageForIssue42827_FilterDropDownStaysVisibleAfterSwitchingFromListToContentPage.cs diff --git a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs index ebfe80533f..f9d58d0e68 100644 --- a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs +++ b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ListViewModel.cs @@ -97,6 +97,17 @@ public partial class ListViewModel : PageViewModel, IDisposable EmptyContent = new(new(null), PageContext); } + private void FiltersPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(FiltersViewModel.Filters)) + { + var filtersViewModel = sender as FiltersViewModel; + var hasFilters = filtersViewModel?.Filters.Length > 0; + HasFilters = hasFilters; + UpdateProperty(nameof(HasFilters)); + } + } + // TODO: Does this need to hop to a _different_ thread, so that we don't block the extension while we're fetching? private void Model_ItemsChanged(object sender, IItemsChangedEventArgs args) => FetchItems(); @@ -586,8 +597,11 @@ public partial class ListViewModel : PageViewModel, IDisposable EmptyContent = new(new(model.EmptyContent), PageContext); EmptyContent.SlowInitializeProperties(); + Filters?.PropertyChanged -= FiltersPropertyChanged; Filters = new(new(model.Filters), PageContext); - Filters.InitializeProperties(); + Filters?.PropertyChanged += FiltersPropertyChanged; + + Filters?.InitializeProperties(); UpdateProperty(nameof(Filters)); FetchItems(); @@ -686,8 +700,10 @@ public partial class ListViewModel : PageViewModel, IDisposable EmptyContent.SlowInitializeProperties(); break; case nameof(Filters): + Filters?.PropertyChanged -= FiltersPropertyChanged; Filters = new(new(model.Filters), PageContext); - Filters.InitializeProperties(); + Filters?.PropertyChanged += FiltersPropertyChanged; + Filters?.InitializeProperties(); break; case nameof(IsLoading): UpdateEmptyContent(); @@ -757,6 +773,7 @@ public partial class ListViewModel : PageViewModel, IDisposable FilteredItems.Clear(); } + Filters?.PropertyChanged -= FiltersPropertyChanged; Filters?.SafeCleanup(); var model = _model.Unsafe; diff --git a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs index 2d750c7df3..62434a632a 100644 --- a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs +++ b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs @@ -70,6 +70,8 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext public bool HasSearchBox { get; protected set; } = true; + public bool HasFilters { get; protected set; } + public IconInfoViewModel Icon { get; protected set; } public PageViewModel(IPage? model, TaskScheduler scheduler, AppExtensionHost extensionHost) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/FiltersDropDown.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/FiltersDropDown.xaml index 36a14965a1..f8c888e8f8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/FiltersDropDown.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/FiltersDropDown.xaml @@ -77,7 +77,7 @@ SelectedValue="{x:Bind ViewModel.CurrentFilter, Mode=OneWay}" SelectionChanged="FiltersComboBox_SelectionChanged" Style="{StaticResource ComboBoxStyle}" - Visibility="{x:Bind ViewModel.ShouldShowFilters, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"> + Visibility="{x:Bind ViewModel.ShouldShowFilters, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed}">