Skip to content

fix(TreeView): Don't reselect a node unselected without a container - #25800

Merged
Xiaoy312 merged 10 commits into
masterfrom
dev/xygu/20261028/treeview-virtualized-selection
Nov 2, 2026
Merged

Xiaoy312 merged 10 commits into
masterfrom
dev/xygu/20261028/treeview-virtualized-selection

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25796

PR Type:

🐞 Bugfix

What changed? 🚀

In a single-selection TreeView, clicking a row after scrolling away from the selected row made the viewport jump back toward the previous row, and SelectionChanged re-added the previous row.

Selecting a node unselects the previous one through TreeViewViewModel.NotifyContainerOfSelectionChange. When the previous node had no container, an Uno-only fallback there assigned it to TreeViewList.SelectedItem even though it was being unselected, which selected it again and scrolled it into view.

  • The fallback now only applies to a node being selected.
  • With a two-way TreeViewItem.IsSelected binding, the unselection of a row without a container never reaches its data, so the row would select itself again once realized (through the TreeView should start with SelectedItem selected #15214 workaround). Such unselections are now recorded on the TreeViewNode with a selection count; when the container is prepared after a newer selection, the stale IsSelected = true is ignored and Selector writes the unselection back to the binding.

The first commit is a contributed patch, kept as is; the following commits refine it (node-based marker instead of a ConditionalWeakTable, a dead reset removed) and tighten the tests.

Tests

New Given_TreeView runtime tests: click after scrolling away (no viewport movement in either direction, previous row not re-added), programmatic replacement (single SelectionChanged, no transient null), scroll-back and collapse/re-expand with an IsSelected binding (old row stays unselected, single selection, SelectedNodes/SelectedItems in sync), and a port of the MUX TreeViewSelectRegressionTest.

Validated on Skia Desktop (Windows): all 31 Given_TreeView tests pass. Disabling each part of the fix makes at least one test fail. With the repro from the issue (20 automated iterations), stock Uno.WinUI 7.0.0-dev.2494 jumps and re-adds the previous row on every iteration; with the fix, none (0/20, on the first commit and again on the final commits).

Given_TreeView is excluded on native WinUI, so the binding scenarios were compared with a standalone WinAppSDK 1.7 app: WinUI also leaves the previous row's bound IsSelected at true while it has no container, but when that row is scrolled back into view it selects it again and then clears the selection, while Uno keeps the clicked row. The tests note this divergence.

Related

PR Checklist ✅

🤖 Generated with Claude Code

jbourque-kahua and others added 9 commits October 28, 2026 14:39
In single selection, selecting a node unselects the previous one through
NotifyContainerOfSelectionChange. When the previous node had no
container, the Uno-only fallback there assigned it to
TreeViewList.SelectedItem even though it was being unselected: that
selected it again and scrolled it into view, then the clicked node's
own selection scrolled back.

Only force a node that is being selected onto the list.

An unselection without a container is not written back to the item's
two-way IsSelected binding, so the data still says true and the
container would select the node again when it is realized. Record such
unselections with the current selection count; when the container is
prepared after another node was selected, ignore the stale value and
reset the container's IsSelected so the binding receives the
unselection.

Fixes #25796

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Selector.PrepareContainerForItemOverride already sets the container's
IsSelected from the list's selection after the stale binding value is
pushed, which writes the unselection back through the binding. The
reset after the base call never found IsSelected still set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Record an unselection made without a container on the TreeViewNode
instead of a ConditionalWeakTable keyed by the list item. In content
mode the key was the item itself, so boxed value types never matched
and equal strings collided.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Uno 7.0 has no native Android or iOS renderer, so the
__ANDROID__ || __APPLE_UIKIT__ ignores never apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The #15214 workaround selects a realized node through
ListViewModel.UpdateSelection, which doesn't clear the other node in
single selection, so also check that only one node is selected and
that SelectedNodes and SelectedItems agree (content-mode aware).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ainer

When_Select_Last_Root_Node_Then_Click_First_Node passed with the
NotifyContainerOfSelectionChange fallback removed, since it only
compared SelectedNodes and SelectedItems. Also check that
TreeView.SelectedItem follows Node 50 while it has no container.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

Checked against WinAppSDK 1.7: after scrolling back, WinUI selects the
previously selected row again and then clears the selection, while Uno
keeps the clicked row. The collapse/re-expand case matches WinUI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242077 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Buttons.png-dark
    • Buttons.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DisplayInformation.png-dark
    • Examples.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DropDownButtonPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png-dark
    • AppWindowFeatures.png-dark
    • AppWindowTitleBar Properties.png
    • Arrange_Performance01.png
    • Attributed_text_Supserscript.png-dark
    • AutoBorderStretchwithleftmargin.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • Basics.png-dark
    • Basics.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242200 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Examples.png
    • DropDownButtonPage.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ImageBrushInList.png-dark
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png
    • AnimatedIconPage.png
    • AppBarButtonWithIconTest.png-dark
    • ApplicationViewMode.png-dark
    • Application_DispatcherShutdownMode.png-dark
    • AppWindowPositionAndSize.png-dark
    • Arrange_Performance01.png
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithleftmargin.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_Relations.png-dark
    • AutomationProperties_Relations.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • BasicAutoSuggestBox.png
    • BasicEnability.png-dark
    • BasicThemeResources.png
    • Battery.png-dark
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png

@Xiaoy312 Xiaoy312 added the 7.0 PRs only. For issues, use the Release field. label Oct 29, 2026
@Xiaoy312
Xiaoy312 enabled auto-merge October 29, 2026 17:49
@Xiaoy312
Xiaoy312 disabled auto-merge October 29, 2026 17:50
@Xiaoy312 Xiaoy312 added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 29, 2026
@mergify

mergify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@Xiaoy312 Xiaoy312 removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 2, 2026
@Xiaoy312
Xiaoy312 merged commit 6f6e88d into master Nov 2, 2026
52 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20261028/treeview-virtualized-selection branch November 2, 2026 15:06
@Xiaoy312

Xiaoy312 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport release/stable/6.7 servicing/6.8

@mergify

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7 servicing/6.8

✅ Backports have been created

Details

agneszitte added a commit that referenced this pull request Nov 2, 2026
…r-25800

fix(TreeView): Don't reselect a node unselected without a container (backport #25800)
agneszitte added a commit that referenced this pull request Nov 3, 2026
…6.7/pr-25800

fix(TreeView): Don't reselect a node unselected without a container (backport #25800)
MartinZikmund added a commit that referenced this pull request Nov 9, 2026
#25800 hooked Selector.ChangeSelectedItem, which the ported Selector
no longer has. Intercept NotifyListItemSelected instead, so a stale
IsSelected pushed while a container is prepared still can't select.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu1xx5N7UDrHyMDxMPa
MartinZikmund added a commit that referenced this pull request Nov 9, 2026
The #25800 tests scrolled row 0 away, but ItemsStackPanel keeps it
realized as its special item, as WinUI does, and never recycles the
focused container. Use row 1 and move focus off it first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu1xx5N7UDrHyMDxMPa
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
#25800 hooked Selector.ChangeSelectedItem, which the ported Selector
no longer has. Intercept NotifyListItemSelected instead, so a stale
IsSelected pushed while a container is prepared still can't select.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu1xx5N7UDrHyMDxMPa
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
The #25800 tests scrolled row 0 away, but ItemsStackPanel keeps it
realized as its special item, as WinUI does, and never recycles the
focused container. Use row 1 and move focus off it first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu1xx5N7UDrHyMDxMPa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TreeView: clicking a row after scrolling away from the selection jumps the viewport and reselects the previous row

6 participants