Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeViewItem Collapses When Its Items Are Removed Until Empty in WinUI 3 #10251

Open
datskiy opened this issue Dec 20, 2024 · 2 comments
Open
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@datskiy
Copy link

datskiy commented Dec 20, 2024

Describe the bug

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.
Image

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.
Image

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.

Steps to reproduce the bug

  1. Run the project: https://github.com/datskiy/TreeViewCollapsingIssue
  2. Observe that the parent TreeViewItem is collapsed and start clicking the 'Remove Item' button until all of them are removed.
  3. Click the 'Restore Item' button to add one item back and observe that the parent TreeViewItem remains 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.

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 as True in XAML.

Source code: https://github.com/datskiy/TreeViewCollapsingIssue

@datskiy datskiy added the bug Something isn't working label Dec 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Dec 20, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@Mangepange
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

2 participants