Originally published on my old Charteris blog

So out of the box WPF's default template will use a VirtualizingStackPanel. The virtualizing part of the VirtualizingStackPanel (VSP) is that it will only generate the UI elements for the items that are currently visible on screen. This can have big benefits when you are working with a large dataset and complex UI.

Things to remember if you think virtualization is not happening

  • Make sure that ScrollViewer.CanContentScroll is set to True & IsVirtualizing is set to True. These are ListBox's defaults but remember them if you are customising the ListBox
  • The VSP is the default content in the ListBox's ItemsPanelTemplate, if you decide you want you ListBox laid out differently you will not be using a VSP and there are no other Virtualizing Panels that ship with WPF
  • It is not always obvious that it is happening. I have had 2000 items in a ListBox with a fairly simple ItemTemplate and have not noticed any difference between Virtualizing being On or Off. Tools like Snoop can be useful to watch the Items in the ListBox being generated as you scroll the contents of the ListBox.