dotnet / dotnet/wpf

TreeView control will cause app to hang when using virtualization + an item in ItemsSource is null

Open
#11,331 1 comment 2 reactions 0 assignees View on GitHub
vsfeedback
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/TreeView-control-will-cause-app-to-hang-/10969048)._

---
[severity:It's more difficult to complete my work]
Found this issue after upgrading a project from .Net Framework 4.8 to .NET 8. It seems there has been a change maybe from prior versions to how virtualization works.

I have a TreeView that gets bound to a list, and found that an app (dispatcher) hang will occur under the specific conditions that:

1: At least one item in the ItemsSource collection is ```null```
2: The ```VirtualizingPanel.IsVirtualizing="true"``` property is set on the TreeView
3: The default style for the ```ItemContainerStyle``` specifies that ```IsExpanded``` is ```true```

If these conditions are met, the app dispatcher will become flooded with calls to ```ArrangeOverride``` ie. will keep trying to rearrange the ```VirtualizingStackPanel``` for some reason, causing all user interactivity to freeze and the application to lock up.

This happens on both .NET 5 and 8 as far as I have tested this.

Please see attached documents for a sample MainWindow XAML and code-behind.

[MainWindow.zip](https://aka.ms/dc/file?name=B9d036ee9ced24a5a849ded4e83a9ad88638937956327612692_MainWindow.zip&tid=9d036ee9ced24a5a849ded4e83a9ad88638937956327612692)

Note that changing either the ItemContainerStyle ```IsExpanded```, the virtualization mode or by removing any null references in the ```ItemsSource``` collection, this "bug" seems to not occur. I suspect something in how ```TreeViewItem```s get rendered means that they keep trying to reevaluate their size in this niche instance where the container has nothing to render, but at this point my knowledge of the WPF layout/virtualization system runs out.

---
### Original Comments

#### Feedback Bot on 19/9/2025, 08:57 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.