Reputation: 115
I just noticed that if I put a GridView or ListView in UWP app inside a HubSection, the UI Virtualization breaks. Is my understanding correct?
Thanks
Upvotes: 1
Views: 1065
Reputation: 10015
Virtualization only happens for items outside the viewport. So it's important to place your GridView
into a control that limits its size (e.g. Grid
without auto-sized rows/columns) or set the size of the control. Wouldn't surprise me if your HubSection
doesn't have a fixed size.
The concept of a viewport is critical to UI virtualization because the framework must create the elements that are likely to be shown. In general, the viewport of an ItemsControl is the extent of the logical control. For example, the viewport of a ListView is the width and height of the ListView element. Some panels allow child elements unlimited space, examples being ScrollViewer and a Grid, with auto-sized rows or columns. When a virtualized ItemsControl is placed in a panel like that, it takes enough room to display all of its items, which defeats virtualization. Restore virtualization by setting a width and height on the ItemsControl.
Also custom templates often break virtualization:
If you provide a custom items panel template (see ItemsPanel) then make sure you use a virtualizing panel such as ItemsWrapGrid or ItemsStackPanel. If you use VariableSizedWrapGrid, WrapGrid, or StackPanel, then you will not get virtualization.
More info on MSDN: UWP and Win8, which also has some good points that still count.
Upvotes: 3