This project is read-only.
Project Description
Virtualizing WrapPanel improves performance when binding a ListBox/ListView to a large amount of data. It is written in C#

Unlike VirtualizingStackPanel which offers the same functionality of StackPanel, this does not fully behave as the default WrapPanel that comes with WPF, there are some reasons for this:

1- WrapPanels can grow in two directions, while StackPanels only grow vertically or horizontally. Also, the growth in the direction orthogonal to the panel's orientation depends on the size of the items in the direction of the panel's orientation, so it is impossible to wrap into a new line/column unless the size of all items on the last line/column is known, but this is impossible if the two directions of the panel are being virtualized(since it does non-pixel based measurement for performance improvement).

2- The size of the extent is the same as the number of lines/columns(sections). On the StackPanel this is not a problem: Since only one item per section is allowed, the extent width/height is the number of items. On the WrapPanel, the number of sections depends highly on the size of items, and since the size of the items is not fixed and can change in any direction, it is impossible to calculate the number of sections on a WrapPanel.

The following solution was adopted when developing this panel:

1- The panel's extent is never known for sure. Instead, the number of sections is estimated after each MeasureOverride using the following expression : 'numberofitems/averageitemspersection'. Since the average number of items per section is updated after each scrolling, the extent of the panel is dynamic. The extent will be static if the items size in the panels orientation is fixed.

2- The items section/sectionindex can only be calculated sequentially, so if you are viewing the first items and you jump to a section that bypasses one or more unrealized sections, the panel will use the estimation to know which item is the first visible, this will be corrected if you go back to a realized section and go back sequentially. For example: if the panel knows that item 12 is in section 1 and the panel estimates 10 items per section,(section 0 is the first), if you jump to section 9 the panel will show the 100th item as the first visible item(that will only be correct if from section 1 to 9 there are exactly 10 items per section). But if you go back to section 1 and access all the sections sequentially until you reach section 9, then the panel will store all the items sections correctly so no further estimations will be made up to section 10.

3- Normally a WrapPanel inside a scrollviewer would be allowed to scroll vertically and horizontally, but since I can only virtualize one direction, this wrappanel will only scroll in the direction orthogonal to the panels orientation.(Meaning you shouldnt set the Virtualizing Panel Height/Width explicitly).

Last edited May 25, 2010 at 4:00 PM by thiagoarruda, version 2