WPF Toolkit DataGrid 滚动性能问题 - 为什么? [英] WPF Toolkit DataGrid scrolling performance problems - why?

查看:35
本文介绍了WPF Toolkit DataGrid 滚动性能问题 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用(WPF 工具包)DataGrid 时遇到了性能问题.它包含大约 1.000 行(只有八列)并且滚动非常缓慢和滞后.包含 DataGrid 的 Window 的初始加载也需要 5-10 秒.

I have a performance problem with the (WPF Toolkit) DataGrid. It contains about 1.000 rows (only eight columns) and scrolling is horribly slow and laggy. Also the initial load of the Window containing the DataGrid takes 5-10 seconds.

我做了一些研究(使用 google 和 StackOverflow),但除了打开 UI 虚拟化的建议之外找不到任何东西.但即使在明确启用滚动之后,仍然非常缓慢.

I did some research (using google and StackOverflow) but couldn't find anything besides the advice to turn on UI virtualization. But even after explictly enabling that scrolling continues to be awfully slow.

我的 DataGrid 绑定到 ICollectionView/CollectionViewSource.它在 XAML 中是这样定义的(列是显式定义的,而不是自动生成的):

My DataGrid is bound to an ICollectionView / CollectionViewSource. It's is defined in XAML like this (the columns are explicitly defined, not auto generated):

    <tk:DataGrid x:Name="dataGrid" 
                 ItemsSource="{Binding Path=Bookings}" 
                 AutoGenerateColumns="False" 
                 Grid.Row="1" 
                 EnableRowVirtualization="True" 
                 EnableColumnVirtualization="True"
                 VirtualizingStackPanel.IsVirtualizing="True"
                 VirtualizingStackPanel.VirtualizationMode="Recycling">
            ... 
    </tk:DataGrid>

整个 Window 的 DataContext 设置为包含 DataGrid 绑定到的 ICollectionView 的类的实例.

The DataContext for the entire Window is set to an instance of the class containing the ICollectionView the DataGrid is bound to.

我发现的每一篇博客或论坛帖子都在赞扬 DataGrid 的性能,所以我很明显做错了什么.由于我对 WPF 总体上很陌生,尤其是对 DataGrid 而言,我不知道如何改进这一点.有人对我有什么建议吗?您对 DataGrid 的体验如何?我做错了什么?

Every blog or forum post I found was praising the DataGrid's performance so I'm quite obviously doing something seriously wrong. Since I'm quite new to WPF in general and especially to the DataGrid I've no clue of how to improve this. Does anybody have some advice for me? What's your experience with the DataGrid? What am I doing wrong?

只是按照这个问题的建议将所有列的宽度设置为自动".这并没有改变糟糕的滚动性能.此外,我没有使用 DataGridTemplateColumns(只是一些 DataGridTextColumns 和两个 DataGridComboBoxColumns).

Just followed this question's advice to set the Width of all columns to "Auto". That did not change the bad scrolling performance. Also I'm not using DataGridTemplateColumns (just some DataGridTextColumns and two DataGridComboBoxColumns).

Edit2:我使用 Snoop 来查看我的应用.我所看到的表明虚拟化确实有效(只有 19 行,而不是 1000 行).但是每行包含 52 个元素,因此这些元素加起来超过一千个元素.这可能是/的问题吗?

I used Snoop to look at my app. What I see suggests that virtualization is indeed working (only 19 rows, not a thousand). But every row contains 52 elements, so those add up to more than thousand elements. Might that be a / the problem?

非常感谢!

推荐答案

在终于抽出时间针对最新版本的 WPF 构建我的应用程序后,滚动问题似乎完全消失了.所以如果有人仍然使用 DataGrid 的工具包版本,只需更新"到框架中包含的版本,你应该没问题.

After finally making the time to build my application against an up-to-date version of WPF the scrolling problem seems completely gone. So if anyone still uses the toolkit version of the DataGrid just "update" to the version included in the framework and you should be fine.

这篇关于WPF Toolkit DataGrid 滚动性能问题 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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