Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF VirtualizingStackPanel for increased performance

I would like a simple description of how to implement a virtualizingstackpanel for an ItemsControl that is databound to an ObservableCollection 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?

like image 746
bluebit Avatar asked Sep 07 '09 14:09

bluebit


1 Answers

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

like image 91
Mike Two Avatar answered Sep 21 '22 00:09

Mike Two