Skip to content

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

Merged
agneszitte merged 10 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25800
Nov 3, 2026
Merged

agneszitte merged 10 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25800

Conversation

@mergify

@mergify mergify Bot commented Nov 2, 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


This is an automatic backport of pull request #25800 done by [Mergify](https://mergify.com).

jbourque-kahua and others added 10 commits November 2, 2026 18:32
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]>
(cherry picked from commit c82c53e)
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]>
(cherry picked from commit 382dde3)
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]>
(cherry picked from commit b83f795)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit b450c33)
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]>
(cherry picked from commit c361665)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit ded8be3)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 94307ba)
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]>
(cherry picked from commit fb219e5)
…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]>
(cherry picked from commit a66e0b5)
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]>
(cherry picked from commit a3f0c7a)
@unodevops

Copy link
Copy Markdown
Contributor

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

@Xiaoy312 Xiaoy312 self-assigned this Nov 2, 2026
@Xiaoy312
Xiaoy312 enabled auto-merge November 3, 2026 01:28
@agneszitte
agneszitte disabled auto-merge November 3, 2026 03:59
@agneszitte
agneszitte merged commit eef1dee into release/stable/6.7 Nov 3, 2026
46 checks passed
@agneszitte
agneszitte deleted the mergify/bp/release/stable/6.7/pr-25800 branch November 3, 2026 03:59
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.

4 participants