UI Virtualization of GridView and ListView in HubSection

不打扰是莪最后的温柔 提交于 2019-12-11 04:12:42

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/38994536/ui-virtualization-of-gridview-and-listview-in-hubsection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!