Thursday, July 28, 2011

What is the different between a StackPanel and a VirtualizingStackPanel

Although it is easy to understand after you’ve tried to use them. I would like to use others explanation about this question. It may help me easy to recall its difference.

First, the original information comes from stackoverflow.com. I reduced its content for easier and faster reading. Go to the original one if you still don’t know what is it mean.

In that article JaredPar said:

A VirtualizingStackPanel can offer performance benefits when working with very large collections. It does so by only rendering and processing a subset of the data which is visible to the user vs. processing the entire list of data (StackPanel). By creating only UI elements for the visible items, this can greatly reduce the amount of work it has to do.

This is really only handy though if

  1. You are data binding non-UI elements or elements for which UI must be created in the particular panel
  2. You are data binding a lot of data

A StackPanel on the other hand, will up front create the controls for all elements contained within the StackPanel.

The VirtualizingStackPanel MSDN page has a decent discussion and samples.

Sohnee added:

This is to do with the visual tree. the VirtualizingStackPanel works with things like ListBox etc. to reduce the size of the visual tree by only displaying visible items - this is useful where data binging is taking place.

No comments:

Post a Comment