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 :)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With