You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removing items sequentially from an expanded TreeViewItem until it is empty causes it to collapse. When items are added back, the parent TreeViewItem unexpectedly remains collapsed. This behavior occurs when the underlying ObservableCollection emits a Remove event for the last item.
A Workaround
If the last item is removed using the Clear method instead of RemoveAt, the ObservableCollection will emit the Reset 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 calling Clear, it will remain collapsed after as expected, so there seems to be no issue with that.
Observe that the parent TreeViewItem is collapsed and start clicking the 'Remove Item' button until all of them are removed.
Click the 'Restore Item' button to add one item back and observe that the parent TreeViewItemremains collapsed.
Expected behavior
The parent TreeViewItem should automatically expand when items are re-added to the source ObservableCollection if it was expanded before removing all the items, like it happens when the Clear method is used.
I experience a similar issue when I reset the source collection in my viewmodel. I perform some sorting logic, and sometimes some of the nodes are collapsed afterwards. Using Remove/Insert on my ObsservableCollection instead of resetting the whole collection makes no difference.
Seems like there are several similiar registered issues out there.
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: