简体   繁体   English

WPF Datagrid非常慢

[英]WPF Datagrid VERY SLOW

i am using a datagrid to display a datatable which contains ~50 rows. 我正在使用数据网格来显示包含约50行的数据表。 For some reason the rendering of the grid is very slow, i takes ~ 2sec to display the grid with the data. 由于某种原因,网格的渲染非常慢,我花了大约2秒的时间来显示带有数据的网格。 If I use a ListBox or a ListView for example the rendering is way faster, which means no delay at all. 例如,如果我使用ListBox或ListView,则渲染速度更快,这意味着完全没有延迟。 The datatable i want to display has 20 columns, but also if i want to display only one column it has no effect on the rendering performance. 我要显示的数据表有20列,但是如果我只想显示一列,则对渲染性能没有影响。

That's the code i am using to display the grid: 那就是我用来显示网格的代码:

    <DataGrid ItemsSource="{Binding Data}" AutoGenerateColumns="True" />

if I set autogeneratecolumns to false (the grid renders the rows but no columns), the grid still needs ~2sec to render 如果我将autogeneratecolumns设置为false(网格渲染行但没有列),则网格仍需要约2秒的时间来渲染

   <DataGrid ItemsSource="{Binding Data}" AutoGenerateColumns="False" />

if i use a listbox instead it has no delay at all (but i need to write a generic template to display all the columns), also ListView has no delays at all 如果我使用列表框而不是完全没有延迟(但是我需要编写一个通用模板来显示所有列),那么ListView也没有任何延迟

    <ListBox ItemsSource="{Binding Data}"/>

I have no idea why the grid is that slow. 我不知道为什么网格这么慢。 I have also tried to set VirtualizingPanel.IsVirtualizing="True" but it had no effect on performance. 我也尝试设置VirtualizingPanel.IsVirtualizing =“ True”,但它对性能没有影响。

Any ideas? 有任何想法吗?

KR Manuel KR曼努埃尔

ALL DataGrid's are horrendously slow (even the ones you pay for). 所有DataGrid的运行速度都非常慢(甚至是您支付的费用)。 You need to turn on virtualization. 您需要打开虚拟化。 VirtualizingStackPanel.IsVirtualizing = true as well as VirtualizingStackPanel.VirtualizationMode = recycling . VirtualizingStackPanel.IsVirtualizing = true以及VirtualizingStackPanel.VirtualizationMode = recycling If you have a lot of columns, or start to do templates, it'll slow to a crawl again. 如果您有很多列,或者开始做模板,那么它将再次缓慢地进行爬网。 Nothing you can do about that really. 您真的无能为力。 I've tried every DataGrid out there (syncfusion, infragistics, etc). 我已经尝试了每个DataGrid(同步融合,基础设施等)。 They are all very slow. 他们都很慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM