[PR #9487] Fix wrong item template selection in CmdPal #27604

Open
opened 2026-01-31 09:22:57 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/9487

State: closed
Merged: Yes


PR Checklist

Detailed Description of the Pull Request / Additional comments

There seems to be a bug in WinUI (see microsoft/microsoft-ui-xaml#2121)
that results in heterogeneous ModernCollectionBasePanel configured
with DataTemplateSelector and virtualization enabled
to recycle a container even if its ContentTemplate is wrong.

I considered few options of handling this:

  • Disabling virtualization (by replacing item container template with
    some non-virtualizing panel (e.g., StackPanel, VirtualizingStackPanel
    with VirtualizationMode=Standard)
  • Replacing DataTemplateSelector approach with ChoosingItemContainer
    event handling approach, which allows you to manage the
    item container (ListViewItem) allocation process.

I have chosen the last one, as it should limit the amount of allocations,
and might allow optimizations in the future.

The solution introduces:

  • A container for ListViewItems in the form of a map of sets:
    • The key of this map is a data template (e.g., TabItemDataTemplate)
    • The value in the set is the container
  • ChoosingItemContainer event handler that looks for available
    item in the container or creates a new one
  • ContainerContentChanging event handler that returns the
    recycled item to the container
**Original Pull Request:** https://github.com/microsoft/terminal/pull/9487 **State:** closed **Merged:** Yes --- ## PR Checklist * [x] Closes https://github.com/microsoft/terminal/issues/9288 * [x] CLA signed. * [ ] Tests added/passed * [ ] Documentation updated. * [ ] Schema updated. * [ ] I've discussed this with core contributors already. ## Detailed Description of the Pull Request / Additional comments There seems to be a bug in WinUI (see microsoft/microsoft-ui-xaml#2121) that results in heterogeneous `ModernCollectionBasePanel` configured with `DataTemplateSelector` and virtualization enabled to recycle a container even if its `ContentTemplate` is wrong. I considered few options of handling this: * Disabling virtualization (by replacing item container template with some non-virtualizing panel (e.g., `StackPanel`, `VirtualizingStackPanel` with `VirtualizationMode`=`Standard`) * Replacing `DataTemplateSelector` approach with `ChoosingItemContainer` event handling approach, which allows you to manage the item container (`ListViewItem`) allocation process. I have chosen the last one, as it should limit the amount of allocations, and might allow optimizations in the future. The solution introduces: * A container for `ListViewItem`s in the form of a map of sets: * The key of this map is a data template (e.g., `TabItemDataTemplate`) * The value in the set is the container * `ChoosingItemContainer` event handler that looks for available item in the container or creates a new one * `ContainerContentChanging` event handler that returns the recycled item to the container
claunia added the pull-request label 2026-01-31 09:22:57 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#27604