WPF DataGrid虚拟化不能正常工作? [英] WPF DataGrid virtualization not working properly?

查看:600
本文介绍了WPF DataGrid虚拟化不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid,它的DataTable集作为它的ItemsSource。
DataTable拥有24列和〜1600行(实际上我将不得不再次加载更多行,但现在这很麻烦)。



尽管为列和行设置了虚拟化,但DataGrid需要大约30秒才能显示这些行。
之后,垂直滚动工作正常,水平是滞后的,虽然你会期待其他方式。



如果我运行内存分析器,我可以验证应用程序使用的大多数内存来自DataGridCells,Borders,ContentPresenters和Textblocks。对我来说,这表明网格没有正确地虚拟化它的行。



任何人都可以确认DataGrid的虚拟化有问题吗?还是在执行这个控件时有什么臭名昭着的陷阱?



期待着任何一种投入/建议。谢谢:)

解决方案

我已经解决了这个问题。
我的DataGrid正坐在一个ScrollViewer中,它可以无限延伸。所以它被认为是认为一切都是可见的,这就是为什么它不会虚拟化它的项目。
我删除了ScrollViewer(DataGrid有自己的滚动条),它现在完美无瑕。


I have a DataGrid which has a DataTable set as its ItemsSource. The DataTable holds 24 columns and ~1600 rows (actually I will have to load alot more rows later on, but for now this is troublesome enough).

Despite setting virtualization for columns and rows active, the DataGrid takes around 30 seconds to display those 1600 rows. After that, scrolling vertically works fine, horizontally is laggy, though you'd expect it the other way around.

If I run a memory profiler, I can verify that most of the memory used by the application comes from DataGridCells, Borders, ContentPresenters and Textblocks. To me, this indicates that the grid does not virtualize its rows properly.

Can anyone confirm that there's an issues with DataGrid's virtualization? Or is there some sort of infamous trap in the implementation of this control?

Looking forward to any kind of input/suggestions. Thanks :)

解决方案

I've solved the issue. My DataGrid was sitting inside a ScrollViewer, in which it would stretch infinitely. So it was fooled into thinking everything was visible, that's why it wouldn't virtualize its items. I removed the ScrollViewer (DataGrid has scrollbars on its own anyway) and it works flawlessly now.

这篇关于WPF DataGrid虚拟化不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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