提高WPF DataGrid的性能 [英] Improve WPF DataGrid performance
问题描述
在我的 .NET 3.5
WPF
应用程序,我有一个 WPF
的DataGrid
将与500列和50行进行填充。
应用程序的性能是非常的滚动非常差,或者当我做 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屋!