WPF虚拟化Treeview中的滚动错误 [英] Scrolling bug in WPF virtualized Treeview

查看:95
本文介绍了WPF虚拟化Treeview中的滚动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPF中使用虚拟化树视图来显示3级深度层次结构,其中包含大量子节点(5000 +).

I'm using a virtualized treeview in WPF to display a 3 level deep hierarchy with a larger number of child nodes (5000+).

<TreeView Grid.Row="0" Grid.Column="0" Name="TestTree"  ItemsSource="{Binding}" VirtualizingStackPanel.IsVirtualizing="True">
...
</TreeView>

发生的事情是,如果我在第3层上展开子节点并滚动到最后,则内容将无法正确显示,并且滚动条会向后翻转",并且我可以永远继续向下滚动,此行为会在之后重复出现一些滚动.

What happens is that if I expand the child nodes on the 3rd level and scroll to the very end the content doesn't display correctly and the scroller "flips back" and I can continue to scroll down forever, the behavior repeating after some more scrolling.

这仅在虚拟化模式下发生,但是不幸的是,由于大量的子节点,非虚拟化模式下树形视图的加载时间令人望而却步.

This only happens in virtualized mode, but unfortunately due to the large number of child nodes the loading time of the treeview in non-virtualized mode is prohibitive.

我在SO 此处和MSDN论坛上的原始主题此处,但是在SelectedItemChanged处理程序中调用 UpdateLayout()的建议解决方法对我不起作用.

I have read the following links on SO here and the original thread on the MSDN forums here but the suggested workaround of calling UpdateLayout() in the SelectedItemChanged handler did not work for me.

其他任何人以前都经历过这种奇怪的行为吗?如果可以的话,是否有解决方法?

感谢任何输入-谢谢!

推荐答案

您是否尝试过延迟加载项目?我的意思是,您可以首先仅加载(不虚拟化)根节点,然后在扩展这些节点中的每个节点时加载其子节点.

have you tryed to load the items lazy?? What i mean is that you could load at first (without virtualizing) only the root nodes, and then when each one of those nodes are expanded load it's childs.

在这种情况下,我通常使用TreeViewItemViewModelClass,例如:

I usually use a TreeViewItemViewModelClass in this cases, something like:

public class TreeViewItemViewModel : INotifyPropertyChanged
{
    public IEnumerable<TreeViewItemViewModel> Childs { get; }
    public bool IsSelected { get; set; }
    public bool IsExpanded { get; set; }
    (...)
}

,然后在具有TwoWay绑定的TreeView的ItemContainerStyle中,绑定IsSelected和IsExpanded属性,然后在属性IsExpanded的setter中加载所有子项.

and then in the ItemContainerStyle of the TreeView with a TwoWay binding bind the IsSelected and the IsExpanded propertires, and then in the setter of the property IsExpanded you load all it's childs.

我已经测试了这种方法,理论上树木有5000多个项目,但从来没有同时加载所有项目.

I have tested this approach, with trees that in theory have more than 5000 items but never with all the items loaded at the same time.

希望这对您有帮助...

Hope this helps...

这篇关于WPF虚拟化Treeview中的滚动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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