TreeView
doesn't preserve the value of IsExpanded
when containers in "content mode" are recycled and reused
#9549
Labels
area-TreeView
bug
Something isn't working
closed-Fixed
Described behavior has been fixed.
fix-released
The fix has been in a release (experimental, preview, stable, or servicing).
team-Controls
Issue for the Controls team
Milestone
Describe the bug
When you expand and collapse nodes in a
TreeView
with anItemsSource
set (i.e. in "content mode"), the value ofTreeViewItem.IsExpanded
is not preserved. If you scroll through a largeTreeView
such that an expanded node is recycled and then you scroll back up, you'll find the node most likely collapsed. Likewise, if you scroll down, you'll find a random node expanded on its own.microsoft-ui-xaml/controls/dev/TreeView/TreeViewList.cpp
Lines 320 to 343 in b91b3ce
This is due to how
TreeViewList.PrepareContainerForItemOverride
is written, where it considers the container the "source of truth" forIsExpanded
, instead of theTreeViewNode
that the container is wrapping. This makes sense only when theItemTemplate
of theTreeView
binds the container'sIsExpanded
to some property in the view model. Otherwise, theTreeViewNode
(which still remembers theIsExpanded
state the last time it was in view) should be the "source of truth".Instead, it could be something like
Steps to reproduce the bug
Click on the buttons from top to bottom.
Expected behavior
Expanded nodes should stay expanded, collapsed nodes should stay collapsed.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.5.2: 1.5.240404000
Windows version
Windows 10 (21H2): Build 19044
Additional context
The text was updated successfully, but these errors were encountered: