Skip to content

fix(itemscontrol): Don't duplicate ItemsStackPanel containers - #26333

Draft
Xiaoy312 wants to merge 8 commits into
dev/xygu/20261111/listbox-portfrom
dev/xygu/20261111/itemscontrol-virtualizing-panel-dupes
Draft

Xiaoy312 wants to merge 8 commits into
dev/xygu/20261111/listbox-portfrom
dev/xygu/20261111/itemscontrol-virtualizing-panel-dupes

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25458, closes #16531

Note

Stacked on #26321 (dev/xygu/20261111/listbox-port): review only the last four commits. Retarget to master once #26321 merges.

PR Type:

🐞 Bugfix

What changed? 🚀

With an ItemsStackPanel as the ItemsPanel of a plain ItemsControl, Uno created two containers per item, and the ones that were laid out all sat at offset 0, on top of each other.

  • Two owners for the panel's children. ItemsControl added a container per item, while the panel's virtualizing layout generated its own. ItemsControl now leaves the children of an ItemsStackPanel (and CarouselPanel, which reuses its layout) to the panel, and refreshes the layout when the items change. Before, nothing told the layout about item changes, so removed or replaced items stayed on screen.
  • VirtualizingStackPanel keeps being managed by a plain ItemsControl, because that's what WinUI does: measured on WinAppSDK, a plain ItemsControl with a VirtualizingStackPanel realizes all 1,000 of 1,000 items, while one with an ItemsStackPanel realizes 15 to 41. So the stacking fallback fix(listbox): Implement ListBox containers and selection #26321 adds for VirtualizingStackPanel matches WinUI.
  • Item changes under other Selectors. With fix(listbox): Implement ListBox containers and selection #26321, the VirtualizingStackPanel of a ListBox (or of any Selector other than ListViewBase and ComboBox) generates its containers from the same layout. fix(listbox): Implement ListBox containers and selection #26321 refreshes it from a ListBox-only UpdateItems override. The refresh now lives in ItemsControl and covers any virtualizing panel whose children the ItemsControl doesn't manage, so that override is removed: keeping both would refresh a ListBox's layout twice per change. ListViewBase forwards changes incrementally and ComboBox already refreshes, so both opt out.
  • Item changes are forwarded incrementally. Instead of refreshing the whole layout, which recycled every realized container and so lost the focus on any insertion or removal (WinUI keeps it), the ItemsControl forwards additions, removals and moves to the panel's layout and repairs the realized containers' indices, as ListViewBase does. ListViewBase's index repair moves to ItemsControl for that. Replaced items rebind their realized containers; grouped sources and resets still refresh.
  • Offset 0. The layout stored the arranged bounds only for ContentControl containers, but a plain ItemsControl's containers are ContentPresenters. The bounds live on UIElement, so they're now stored for any container.

Not covered here:

  • Uno's layout still realizes every item under a plain ItemsControl, where WinUI virtualizes: the layout only follows a ScrollViewer found before reaching the ItemsControl, and assumes the panel starts at the scroll origin. Inside an outer ScrollViewer the panel also reports only the viewport's height, so it doesn't scroll. That was already the case before this PR.
  • ItemsWrapGrid is still an unimplemented stub on Skia, so it shows nothing under a plain ItemsControl.
  • WinUI rejects a CarouselPanel outside of a ComboBox; Uno keeps accepting it.

Validation

  • Runtime, Skia desktop:
    • the new Given_ItemsControl tests fail on fix(listbox): Implement ListBox containers and selection #26321 alone (5 of them) and pass with the fixes. The new Given_ListBox containers test passes on fix(listbox): Implement ListBox containers and selection #26321 alone too, because of the override this PR replaces; it guards the generic path. The new Given_ListBox focus test fails without the incremental forwarding (the focus leaves the list on an insertion far below the viewport) and passes with it;
    • Given_ItemsControl, Given_ListBox, Given_VirtualizingStackPanel, Given_ComboBox, Given_ListViewBase, Given_ListViewBase_Items, Given_FlipView, Given_GridView_Items, Given_TabView, Given_CalendarView, Given_ItemsStackPanel, Given_Selector, Given_AccessibleListView: 305 passed, 0 failed, 22 skipped, 1 inconclusive (When_Large_List_Scroll_To_End_Then_Back_Up_TryClick, also inconclusive on master).
  • Runtime, native WinUI (WinAppSDK): Given_ItemsControl, Given_ListBox, Given_VirtualizingStackPanel: 48/48 pass, including the new tests. 6 are skipped: the CarouselPanel one, since WinUI rejects that panel, and fix(listbox): Implement ListBox containers and selection #26321's Uno-only input tests.
  • Not run: WebAssembly, Android, iOS.

PR Checklist ✅

🤖 Generated with Claude Code

@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/listbox-port branch from b21d4b0 to 13dd4d5 Compare November 12, 2026 05:25
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/listbox-port branch from 13dd4d5 to 3f60a9b Compare November 12, 2026 07:04
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/itemscontrol-virtualizing-panel-dupes branch from fa88651 to 13fa8c1 Compare November 12, 2026 07:04
Xiaoy312 and others added 8 commits November 12, 2026 02:58
VirtualizingStackPanel threw from GetLayouter on Skia, so any ItemsControl
using it, like the default ListBox template, showed no items. Under a
Selector it now borrows ItemsStackPanelLayout, like CarouselPanel, and
creates it only then; under a plain ItemsControl, which adds the containers
itself, it stacks them without virtualizing, as WinUI does. Orientation is
implemented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moves it to Selector so other selectors on a virtualizing panel can use it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ports ListBox_Partial.cpp: ListBoxItem containers, SelectionMode (Single,
Multiple, Extended with an anchor), SelectedItems, SelectAll,
SingleSelectionFollowsFocus, ScrollIntoView, and keyboard navigation and
selection. Uno's Selector has no multi-selection store, so, as in
ListViewBase, SelectedItems holds it and SelectedIndex/SelectedItem follow
its first item; item changes, SelectionMode and ItemsSource changes, and
app changes to SelectedItems behave as on WinUI. Selector's checks for its
subclasses become virtual members, so UI Automation's
AddToSelection/RemoveFromSelection work for a ListBox too.

Fixes #1362

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A manual test page for the selection modes: clicks with modifiers, the
keyboard, SingleSelectionFollowsFocus, SelectAll and item insertions,
with the selection and the SelectionChanged events shown next to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plain ItemsControl added a container per item to an ItemsStackPanel
(or CarouselPanel) while the panel's layout generated its own, so every
item had two containers, and item changes never reached the layout.

The ItemsControl now leaves those panels' children to their layout and
refreshes it on item changes. A VirtualizingStackPanel stays managed by
the ItemsControl: WinUI realizes all of its items there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under a Selector other than ListViewBase and ComboBox (ListBox, FlipView,
...), a VirtualizingStackPanel generates its containers from its borrowed
ItemsStackPanel layout, but the ItemsControl only refreshed the layout of
an ItemsStackPanel or CarouselPanel on item changes. It now refreshes the
layout of any virtualizing panel whose children it doesn't manage.

This replaces ListBox's own UpdateItems override, which refreshed the same
layout a second time on every item change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The virtualizing layout only recorded the bounds of ContentControl
containers, so the ContentPresenter containers of a plain ItemsControl
were all arranged at offset 0 and overlapped. The bounds live on
UIElement, so record them for any container.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An item change under a panel that generates its own containers (a
ListBox's VirtualizingStackPanel, an ItemsControl's ItemsStackPanel)
refreshed the whole layout, which recycled every realized container: the
focused item lost the focus on any insertion or removal, even one far
outside the viewport. The ItemsControl now forwards additions, removals
and moves to the layout and repairs the realized containers' indices, as
ListViewBase does (its index repair moves to ItemsControl), and rebinds
the realized containers of replaced items. Grouped sources and resets
still refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/listbox-port branch from 3f60a9b to 466ca06 Compare November 12, 2026 08:49
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/itemscontrol-virtualizing-panel-dupes branch from 13fa8c1 to c3158fd Compare November 12, 2026 08:49
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/listbox-port branch from 466ca06 to 06595d2 Compare November 12, 2026 17:59
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261111/listbox-port branch from 06595d2 to 41f25fd Compare November 25, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant