HypernovaDesktop Components · docs
Binarymission
WPF › Virtualizing Wrap Panel

Virtualizing Wrap Panel

.NET Framework 4.8.NET 6 / 8 / 10v9.0.0WPF

A wrap panel for an items control that creates only the items in view: items flow along a line and wrap onto the next, as in a WrapPanel, but a ListBox of fifty thousand tiles scrolls as lightly as one of fifty.

7public types
104public members
2namespaces

Assembly

AssemblyBinarymission.WPF.Controls.VirtualizingWrapPanel.dll
Root namespaceBinarymission.WPF.Controls.Panels
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10
Depends onVirtualizingCollectionView

Overview

Use it as the ItemsPanel of a ListBox – or any items control whose template has a ScrollViewer with content scrolling on – wherever a long list reads better as tiles than as rows: photo galleries, product catalogues, file browsers, dashboards of cards.

How it virtualises

The panel is its own scroll owner (IScrollInfo). On each measure it works out from the offset and the viewport which items are in view, has containers created for those alone, and keeps or removes the ones that have left the view as VirtualizationSchemeOption says. Everything else exists only as data, in ItemsControl.ItemsSource.

Two layouts

By default each item gets a cell of ItemDimension, which you must set. A line holds as many cells as fit (see ItemPositioningMode) and an item's place is arithmetic on its index, so a jump to any item is cheap. With IsVariableItemSizeEnabled or IsDataSourceGrouped, a flow layout gives each item its own measured size instead.

Scrolling and grouping

Orientation gives rows that scroll down (the default) or columns that scroll across, a line – one item – at a time; ScrollToTheDesiredChild takes the user to any item. For groups, bind the items control to a VirtualizingCollectionView, which presents each group's header as a row of the flat list, and set IsDataSourceGrouped: the headers are laid out as GroupVirtualizationMode says and virtualised with the items.

Things to know

Getting started

A product catalogue as 180 by 140 tiles; Products holds objects with Name and Price.

<ListBox xmlns:vwp="clr-namespace:Binarymission.WPF.Controls.Panels;assembly=Binarymission.WPF.Controls.VirtualizingWrapPanel"
         ItemsSource="{Binding Products}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <vwp:BinaryVirtualizingWrapPanel ItemDimension="180,140" ItemPositioningMode="Safe" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="8">
                <TextBlock Text="{Binding Name}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
                <TextBlock Text="{Binding Price, StringFormat=C}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

API reference

Binarymission.WPF.Controls.Panels

class BinaryVirtualizingWrapPanelA wrap panel for an items control that creates only the items in view: items flow along a line and wrap onto the next, as in a WrapPanel, but a ListBox of fifty thousand tiles scrolls as lightly as one of fifty.
enum AnimationEffectLists the transitions the panel can play as it scrolls, for PanelAnimationEffect.
enum VirtualizationSchemeLists what the panel does with the container of an item (the ListBoxItem, say) once the item has left the view. The data item itself is never touched.

Binarymission.WPF.Controls.Panels.VirtualizingWrapPanel

class AboutToRenderChildItemsEventArgsProvides the data for AboutToRenderChildItems: the range of items the panel is about to show.
enum GroupVirtualizationModeLists how BinaryVirtualizingWrapPanel lays out the group headers of a grouped source.
interface ISupportTransactionalUpdatesLets code tell a virtualising panel that its data has been edited, so that it brings what is on screen up to date at once.
enum ItemPositioningModeLists what BinaryVirtualizingWrapPanel does with space at the end of a line too narrow for a whole item, in its fixed-size layout.