WPF中具有不同方向的Virtualized TreeView是否无法虚拟化? [英] WPF Virtualized TreeView with different orientations within doesn't virtualize?

查看:150
本文介绍了WPF中具有不同方向的Virtualized TreeView是否无法虚拟化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XAML中有多层的TreeView.使用此解决方案,我可以为每个不同的层获得XAML配置的外观,并确认它是UI虚拟化的.

I have a TreeView in XAML with multiple layers. Using this solution I can get a XAML-configured look for each of the different layers, and confirmed that it is UI virtualizing.

但是,当我将特定图层的VirtualizingStackPanel切换为具有不同的Orientation时(是否通过此解决方案,或与父解决方案一起使用 Snoop ),然后关闭UI虚拟化,然后扩展该层后,TreeView就会实现所有TreeViewItem.

However, when I switch a particular layer's VirtualizingStackPanel to have a different Orientation (it doesn't matter whether through code like this solution, or with Snoop) than its parent, then UI virtualization switches off and the TreeView realizes all the TreeViewItems as soon as I expand that layer.

在研究此行为时,我注意到在深入研究MeasureOverride函数时,在VirtualizingStackPanel的参考源中,您会找到

While researching this behavior I noticed that within the reference source for VirtualizingStackPanel as you drill into its MeasureOverride function, you find this comment on line 2116:

计算此面板的方向是否不同于其父级或后代

Compute if this panel is different in orientation that (sic) either its parent or descendents

在这种情况下,Microsoft似乎故意禁用了UI虚拟化.所以我有两个问题:

It appears that Microsoft has intentionally disabled UI virtualization for this case. So I have two questions:

  • 为什么各层之间的方向一致很重要?
  • 如何使UI虚拟化与具有不同方向的TreeView一起使用?
  • Why does it matter to have orientation consistency between layers?
  • How can I get UI virtualization to work with a TreeView having different orientations within it?

推荐答案

UI虚拟化依赖于能够正确测量视口和应该在视场中的内容的能力.一般而言,如果您要在一个维度上滚动以实现类似列表的结构(将树视图认为是缩进的列表(就渲染而言)而言),则效果很好.如果突然不得不根据要渲染的孩子在两个维度上进行计算,则效果不佳.想一想如果这些水平方向的子项中的一个子项比其他子项高,但当前在屏幕上不可见,该算法必须如何处理-如何确定下一个垂直子项是否在视图中而无需计算布局为所有这些孩子而战胜了虚拟化的目的吗?

UI Virtualization relies on the ability to correctly measure the viewport and the contents that should be in view. Generally speaking, that works out well if you're scrolling in one dimension for a list-like structure (thinking of the tree view as, say, an indented list as far as rendering goes). It doesn't work out as well if you suddenly have to calculate that in two dimensions, depending on which child you're rendering. Think of what the algorithm has to work through if one of those horizontally oriented children is taller than others, but isn't currently visible on the screen - how does it determine if the next vertical child should be in view or not without calculating the layout for all of those children, thus defeating the purpose of virtualization?

这篇关于WPF中具有不同方向的Virtualized TreeView是否无法虚拟化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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