VirtualizingWrapPanel
This article will describe the VirtualizingWrapPanel and how it can be used as an ItemsPanel for a RadListBox.
Key Properties
- ItemHeight: Gets or sets a value that specifies the Height of all items that are contained within a VirtualizingWrapPanel.
- ItemWidth: Gets or sets a value that specifies the Width of all items that are contained within a VirtualizingWrapPanel.
-
ScrollStep: Gets or sets a value for the amount that will be scrolled when using the mouse wheel or the scrollbar buttons (Not supported when grouping is enabled).
Scrolling with the Page up and Page down keys and navigating with the Left and Right arrow keys is not supported when grouping is enabled.
VirtualizingPanel.ScrollUnit : The possible values are Pixel (the scrolling is pixel based) and Item (the scrolling is item based). (When grouping is enabled, only Pixel is supported). The default value is Item.
- VirtualizingPanel.IsVirtualizingWhenGrouping : Set this property to True to enable virtualizing when grouping.
-
VirtualizingPanel.VirtualizationMode: Specifies the method the panel will use to manage virtualizing its child items. The possible values are Standard (create and discard the item containers) and Recycling (reuse the item containers).
The ScrollUnit, IsVirtualizingWhenGroupinga and VirtualizationMode properties are available in .NET 4.6.2 and later.
VirtualizingWrapPanel
In order to demonstrate how the VirtualizingWrapPanel can be used, we will setup some sample data as demonstrated in Example 1.
Example 1: Setting up the model and viewmodel
Setting up the RadListBox
Example 2 demonstrates how the VirtualizingWrapPanel can be used as an ItemsPanel for a RadListBox. You can read some more about the benefits of UI Virtualization in the following article.
Example 2: RadListBox with VirtualizingWrapPanel as ItemsPanel
Figure 1: Result from Example 2 in the Office2016 theme
Grouping
Example 3 demonstrates how you can apply grouping to the data by setting the GroupStyle property. Otherwise, the example uses the same setup as Example 2.
Example 3: Grouped RadListBox with VirtualizingWrapPanel as ItemsPanel
Grouping and Virtualization
The VirtualizingWrapPanel supports virtualization when the data is grouped. This feature is only available for .NET 4.6.2 and above.
In order to turn on this feature, you have to set the VirtualizingPanel.IsVirtualizingWhenGrouping attached property to True.
Additionally, you have to set the VirtualizingPanel.ScrollUnit to Pixel, since VirtualizingPanel.ScrollUnit="Item" is not supported while grouping. Optionally, you can also set the VirtualizingPanel.VirtualizationMode property to Recycling in order for the item containers to be recycled during scrolling.
Example 4: Turning on virtualization while grouping
Note that you also need to set the attached properties on the panel in the GroupStyle as they will not be transferred automatically.
When the VirtualizingPanel.IsVirtualizingWhenGrouping property is set to True, the VirtualizingPanel.ScrollUnit needs to be Pixel, since VirtualizingPanel.ScrollUnit="Item" is not supported.