views:

2214

answers:

2

I would like a simple description of how to implement a virtualizingstackpanel for an ItemsControl that is databound to an observable collection in my MVVM.

I have an ItemsControl instance for each tab in a tab control, and switching tabs becomes VERY slow when the ItemsControl grows larger.

What can I do to speed up the app?

I opened up a WPF profiler and saw that each element (which is a custom user control) displayed in my ItemsControl of each tab had its own ContentPresenter. So I essentially had 100 content presenters all running for 100 items in my observablecollection in MVVM. Is this corrrect? How can I optimize?

+3  A: 

There are two techniques that might be a big help. Both of them are described very well by Bea Stolnitz on her blog.

The first is UI Virtualization and the second is Data Virtualization

In UI virtualization you use things like VirtualizingStackPanel to make the UI draw fewer things.

Data virtualization makes sure you don't bring a million objects into memory when you are only going to show 100.

So UI virtualization minimizes the number of things drawn and data virtualization minimizes the number of things that could be drawn.

Hope that helps

Mike Two
+4  A: 

I had exact the same problem ind WPF using TabControl and DataGrid. By growing DataGrid element size, switching tabs becomes VERY slow ! After that I found this post reading the blog from Bea Stolnitz as supposed by the previous answer. That gave me the hint to google "wpf tabcontrol VirtualizingStackPanel" which gives me the link to DrWPF: http://groups.google.com/group/wpf-disciples/browse%5Fthread/thread/6f3531a1720252dd

He descripes excatly the problem and gives the solution :-))

.... The perf hit is during the building of the tree. Unfortunately, if
you're using a typical MVVM approach with a binding on the ItemsSource
property of the TabControl, the entire tree must be rebuilt each time
a tab item is selected. This is usually a very expensive operation. ....