HubSection中GridView和ListView的UI虚拟化 [英] UI Virtualization of GridView and ListView in HubSection

查看:48
本文介绍了HubSection中GridView和ListView的UI虚拟化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到,如果我将 GridView 或 ListView 放在 UWP 应用中的 HubSection 中,UI 虚拟化就会中断.我的理解正确吗?

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?

谢谢

推荐答案

虚拟化只发生在视口之外的项目.因此,将 GridView 放入限制其大小的控件(例如 Grid 没有自动调整大小的行/列)或设置控件的大小非常重要.如果您的 HubSection 没有固定大小,我不会感到惊讶.

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.

视口的概念对于 UI 虚拟化至关重要,因为框架必须创建可能显示的元素.在一般来说,ItemsControl 的视口是逻辑的范围控制.例如,ListView 的视口是宽度和ListView 元素的高度.一些面板允许子元素无限空间,例如 ScrollViewer 和 Grid,自动调整大小的行或列.放置虚拟化 ItemsControl 时在这样的面板中,需要足够的空间来显示其所有项目,这打败了虚拟化.通过设置恢复虚拟化ItemsControl 上的宽度和高度.

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:

如果您提供自定义项目面板模板(请参阅 ItemsPanel),则确保您使用虚拟化面板,例如 ItemsWrapGrid 或项目堆栈面板.如果您使用 VariableSizedWrapGrid、WrapGrid 或StackPanel,那么你就得不到虚拟化.

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.

有关 MSDN 的更多信息:UWPWin8,其中也有一些值得重视的优点.

More info on MSDN: UWP and Win8, which also has some good points that still count.

这篇关于HubSection中GridView和ListView的UI虚拟化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆