WPF DataGrid virtualization not working properly?

一个人想着一个人 提交于 2019-12-10 15:45:00

问题


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 :)


回答1:


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.




回答2:


Hmm, ok I don't know why but obviously I've to add some glue text to post an answer here. Maybe, this SO answer will help you.

Edit

As additional advice I'd like to recommend you to think about your approach. Is it really necessary to add 1.6k+ items to a DataGrid? Perhaps you should think about deferred loading.



来源:https://stackoverflow.com/questions/14958116/wpf-datagrid-virtualization-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!