TreeViewItem Collapses When Its Items Are Removed Until Empty in WinUI 3 #10251
Labels
area-TreeView
bug
Something isn't working
product-winui3
WinUI 3 issues
team-Controls
Issue for the Controls team
Describe the bug
Removing items sequentially from an expanded
TreeViewItem
until it is empty causes it to collapse. When items are added back, the parentTreeViewItem
unexpectedly remains collapsed. This behavior occurs when the underlyingObservableCollection
emits aRemove
event for the last item.A Workaround
If the last item is removed using the
Clear
method instead ofRemoveAt
, theObservableCollection
will emit theReset
event, which will not cause this issue. However, I still find it very unintuitive and it is particularly inconvenient when the source collection is controlled by a 3rd party library, like DynamicData.FYI: if the parent
TreeViewItem
was collapsed before callingClear
, it will remain collapsed after as expected, so there seems to be no issue with that.Steps to reproduce the bug
TreeViewItem
is collapsed and start clicking the 'Remove Item' button until all of them are removed.TreeViewItem
remains collapsed.Expected behavior
The parent
TreeViewItem
should automatically expand when items are re-added to the sourceObservableCollection
if it was expanded before removing all the items, like it happens when theClear
method is used.Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003
Windows version
Windows 11 (24H2): Build 26100
Additional context
The
IsExpanded
property is set asTrue
in XAML.Source code: https://github.com/datskiy/TreeViewCollapsingIssue
The text was updated successfully, but these errors were encountered: