WPF TreeView Memory Consumption and Performance

One very simple thing you can do that can significantly reduce the memory consumption and drastically improve performance of a WPF TreeView is to set the following two properties. In XAML, you would do:

<TreeView x:Name=”myTreeView”


          VirtualizingStackPanel.VirtualizationMode="Recycling" />

In a simple test of a data-bound TreeView containing just 5000 items, turning on stack panel virtualization reduces the memory overhead from over 110MB to about 2MB. Additionally, the control also gets a performance boost in items’ expand/collapse, selection, scrolling, and general navigation.

The WPF ListView also support these properties but, unlike the TreeView, its VirtualizingStackPanel.IsVirtualizing is already default to True.



Comments (3)
  1. Dave Allen says:

    Thanks for this one Tan! You made my day. Still really slow filling it up dynamically, but at least the performance for opening and closing a branch is greatly improved.

  2. Eldar says:

    Thank you!!!! )))) It's very help me!

  3. System.Cats.Lol says:

    Awesome tip! Couldn't figure out why our TreeView was sluggish. This fixed it!

Comments are closed.

Skip to main content