--- title: "How to: Improve the Performance of a TreeView" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "TreeView control [WPF], improving the performance" ms.assetid: b792c740-cf2b-4da8-8ba8-3d2e5a821874 --- # How to: Improve the Performance of a TreeView If a contains many items, the amount of time it takes to load may cause a significant delay in the user interface. You can improve the load time by setting the `VirtualizingStackPanel.IsVirtualizing` attached property to `true`. The UI might also be slow to react when a user scrolls the by using the mouse wheel or dragging the thumb of a scrollbar. You can improve the performance of the when the user scrolls by setting the `VirtualizingStackPanel.VirtualizationMode` attached property to . ## Example ## Description The following example creates a that sets the `VirtualizingStackPanel.IsVirtualizing` attached property to true and the `VirtualizingStackPanel.VirtualizationMode` attached property to to optimize its performance. ## Code [!code-xaml[RecycleItemContainerShippets#VirtualizingTreeView](~/samples/snippets/csharp/VS_Snippets_Wpf/RecycleItemContainerShippets/CSharp/Window1.xaml#virtualizingtreeview)] The following example shows the data that the previous example uses. [!code-csharp[RecycleItemContainerShippets#TreeViewData](~/samples/snippets/csharp/VS_Snippets_Wpf/RecycleItemContainerShippets/CSharp/Window1.xaml.cs#treeviewdata)] [!code-vb[RecycleItemContainerShippets#TreeViewData](~/samples/snippets/visualbasic/VS_Snippets_Wpf/RecycleItemContainerShippets/visualbasic/window1.xaml.vb#treeviewdata)] ## See also - [Controls](../advanced/optimizing-performance-controls.md)