WPF DataGrid is extremly slow, how can I improve the Initial Loading time?
I have a Window with a DataGrid showing grouped Data.
开发者_运维百科I am loading around 4 x 300 items in the WPF DataGrid which are grouped in 4 groups.
Grouping disables Virtualization.
I set IsAsync="True" so my Window opens fast but the DataGrid is just filled AFTER 11 SECONDS ???
What can I do to speed up the loading/display of my data?
You stated it yourself - grouping disables virtualization; I think for now showing each group separately (in its own datagrid) is the way to go if at all possible... or some other similar trick to simply not show all the items using grouping.
Much later edit: There's actually quite an interesting write-up at http://jerryclin.wordpress.com/2008/02/22/listbox-grouping-and-virtualization/ on how to go about doing things if you REALLY need ListBox grouping with virtualization. Not sure it's worth the pain, but it's possible.
Not sure if its related, but I had a similar problem with the DataGrid in which it took literally seconds to refresh after a window resize, column sort, etc. and locked up the window UI while it was doing so (1000 rows, 5 columns).
It came down to an issue (bug?) with the WPF sizing calculations. I had it in a grid with the RowDefinition Height="Auto" which was causing the rendering system to try and recalculate the size of the DataGrid at runtime by measuring the size of each and every column and row, presumably by filling the whole grid (as I understand it). It is supposed to handle this intelligently somehow but in this case it was not.
A quick check to see if this is a related problem is to set the Height and Width properties of the DataGrid to a fixed size for the duration of the test, and try running again. If your performance is restored, a permanent fix may be among these options:
- Change the sizes of the containing elements to be relative (*) or fixed values
- Set MaxHeight and MaxWidth of the DataGrid to a fixed value larger than it could get in normal use
- Try another container type with different resizing strategy (Grid, DockPanel, etc)
In .NET 4.5.2 virtualizing grouped items is finally possible:
<DataGrid VirtualizingPanel.IsVirtualizingWhenGrouping="True" />
https://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingpanel.isvirtualizingwhengrouping%28v=vs.110%29.aspx
精彩评论