-
Notifications
You must be signed in to change notification settings - Fork 7.6k
CmdPal: Fix FiltersViewModel binding #42467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CmdPal: Fix FiltersViewModel binding #42467
Conversation
Removes runtime binding from FiltersDropDown control.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
## Summary of the Pull Request This PR resolves crashes on pages with filters, such as Windows Terminal profiles or Windows Services, when compiled with trimming/AOT. It removes runtime binding from the FiltersDropDown control, effectively preventing crashes caused by trimming/AOT dropping binding metadata for FilterItemViewModel. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #42428 - [x] Closes: #42482 - [x] Related to: #42458 - [ ] **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 <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Co-authored-by: Niels Laute <[email protected]>
Hotfixes #42467 #42434 #42405 #42399 --------- Co-authored-by: Jiří Polášek <[email protected]> Co-authored-by: Niels Laute <[email protected]> Co-authored-by: Jaylyn Barbee <[email protected]> Co-authored-by: Gordon Lam <[email protected]> Co-authored-by: Dustin L. Howett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the filter selection mechanism in the Command Palette to bind directly to filter objects instead of using IDs. The change simplifies the XAML binding by removing the SelectedValuePath property and binding SelectedValue to the new CurrentFilter property instead of CurrentFilterId.
- Replaced XAML binding from ID-based to object-based selection in FiltersDropDown
- Added
CurrentFilterproperty toFiltersViewModelto track the selected filter object - Refactored
BuildFiltersmethod to return both filter items and the selected filter object in a tuple
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/FiltersDropDown.xaml | Simplified ComboBox binding to use CurrentFilter object directly instead of CurrentFilterId with SelectedValuePath |
| src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/FiltersViewModel.cs | Added CurrentFilter property and refactored BuildFilters to identify and return the selected filter object |
| })]; | ||
| } | ||
|
|
||
| return (items.ToArray(), selectedFilterItem ?? firstFilterItem); |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When separators are present in the filters list, firstFilterItem might be null if the first item in the filters array is a separator (not an IFilter). This could return null as the selected filter even when there are valid filter items later in the list. Consider finding the first FilterItemViewModel in the items list instead of tracking it during iteration, or ensure firstFilterItem is only set once a valid filter is found.
| private (IFilterItemViewModel[] Items, IFilterItemViewModel? Selected) BuildFilters(IFilterItem[] filters, string currentFilterId) | ||
| { | ||
| return [..filters.Select<IFilterItem, IFilterItemViewModel>(filter => | ||
| if (filters is null || filters.Length == 0) |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null check for filters is redundant since the parameter is already guarded with the null-coalescing operator (filters ?? []) at the call site on line 39. Consider removing the null check and only checking for length.
| if (filters is null || filters.Length == 0) | |
| if (filters.Length == 0) |
## Summary of the Pull Request This PR resolves crashes on pages with filters, such as Windows Terminal profiles or Windows Services, when compiled with trimming/AOT. It removes runtime binding from the FiltersDropDown control, effectively preventing crashes caused by trimming/AOT dropping binding metadata for FilterItemViewModel. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: microsoft#42428 - [x] Closes: microsoft#42482 - [x] Related to: microsoft#42458 - [ ] **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 <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Co-authored-by: Niels Laute <[email protected]>
Summary of the Pull Request
This PR resolves crashes on pages with filters, such as Windows Terminal profiles or Windows Services, when compiled with trimming/AOT.
It removes runtime binding from the FiltersDropDown control, effectively preventing crashes caused by trimming/AOT dropping binding metadata for FilterItemViewModel.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed