提高 WPF DataGrid 性能 [英] Improve WPF DataGrid performance

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

问题描述

在我的 .NET 3.5 WPF 应用程序中,我有一个 WPF DataGrid 将填充 500列和 50 行.App在滚动、DataGrid.Items.Refresh()或选择行时的性能非常差.

In my .NET 3.5 WPF Application, I have a WPF DataGrid which will be populated with 500 columns and 50 rows. The performance of App is very very poor in scrolling, or when I do DataGrid.Items.Refresh() or in selecting rows.

实际上应用程序需要大约 20 秒来更新布局.Layout_Updated() 事件将在 20 秒后触发.

Actually App will take around 20 sec to Update Layout. Layout_Updated() event will trigger after 20 sec.

如果我将列减少到 50 或更少,应用程序将非常敏感.根据我的发现,性能与列数直接相关.

If I reduce the columns to 50 or less, App will be very responsive. As per my findings performance is directly related to column count.

如何提高 DataGrid 的性能?

推荐答案

您可以打开几个选项来帮助您处理 DataGrid 对象

There are a few options you can turn on to help you on your DataGrid object

EnableColumnVirtualization = true
EnableRowVirtualization = true

这两个是我认为可能会有所帮助的主要内容.接下来尝试使您的绑定异步

These two are the main ones I think might help. Next try making your binding async

ItemsSource="{Binding MyStuff, IsAsync=True}"

最后,我听说设置最大高度和宽度会有所帮助,即使它高于最大屏幕尺寸,但我自己没有注意到有什么不同(声称与自动尺寸测量有关)

And lastly, I've heard that setting a maximum height and width can help even if it above the max screen size, but I didn't notice a difference myself (claim had to do with auto size measuring)

MaxWidth="2560"
MaxHeight="1600"

也永远不要将 DataGrid 放在 ScrollViewer 中,因为你基本上会失去虚拟化.如果这有帮助,请告诉我!

Also never put a DataGrid in a ScrollViewer, because you will essentially lose virtualization. Let me know if this helps!

这篇关于提高 WPF DataGrid 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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