Geeks With Blogs
Sam Abraham Software Engineer/Architect: Putting Customers First
In WPF, the TreeView control empowers developers with the ability to display hierarchical content with great ease and convenience.
 
However, while load testing a TreeView control, we saw significant slowness on application startup. Contrary to our initial expectations, benchmarks showed that the bulk of the wait time is actually spent binding the data to and updating the TreeView interface while only a few seconds were spent retrieving and building the data model.
 
That led us to learn more about UI virtualization.  To briefly share with those who might not know, virtualization only binds the currently viewable data portion to the UI. This becomes very helpful when incorporated with scrolling as it would cause data to be loaded a small portion at a time.
 
However, enabling virtualization flags on our TreeView control didn’t seem to improve performance. Further research suggested that in WPF, a TreeView control does not support UI virtualization.
 
To tackle this problem, we resorted to implementing a hierarchical ListView solution to render the desired user interface layout while leveraging the virtualization feature supported by the ListView control.
 
We found a nice post containing a good proof-of-concept which helped us accomplish our task quicker. Additionally, we implemented lazy loading, where only the top level of our hierarchical ListView is loaded on startup with child nodes loaded on-demand as parent node is expanded.
 
To Leverage virtualization for a WPF control we need to add the following attributes to the XAML definition of the control:
 

<Grid x:Name="LayoutRoot"

VirtualizingStackPanel.IsVirtualizing="True"  VirtualizingStackPanel.VirtualizationMode="Recycling"/>

 
To implement Lazy loading for child tree nodes, a dummy empty child node need to be inserted to each parent node. The event triggered from expanding a node would then replace the dummy node with actual child data on-demand.
 
--Sam Abraham
Posted on Wednesday, October 20, 2010 8:35 AM Fladotnet.com , Tech Talk , VS2010 , MVVM , WPF | Back to top


Comments on this post: All in a Day’s Work: WPF TreeView Performance Degradation for Large Data Sources

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sam Abraham | Powered by: GeeksWithBlogs.net