I have tried using both a customized DataGrid as well as the stock one in WPF. I have tried populating them manually as well as through bindings. In both cases they are sl
A blog I found on Google gave me a sort-of solution. As the author said, I disabled GroupStyle, and the rendering speed issue was solved. But I needed grouping. The author said
VirtualizingPanel.IsVirtualizingWhenGrouping
is added to .NET 4.5. So I set it to true. Now rendering is quick with grouping. The problem is... scrolling is jerky. Not unacceptably jerky, but noticeably jerky. I had similar problem when I tried to create a TreeView with 2000+ nodes expanded. Without virtualisation, rendering was slow but scrolling was smooth. With virtualisation, rendering was quick but scrolling was jerky.
Why can't we have both...
For me it was:
<Setter Property='ScrollViewer.CanContentScroll' Value='False' />
I removed this from the style and the rendering became fast.
A general tip for DataGrid
performance issues: I had a 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:
MaxHeight
and MaxWidth
of the DataGrid to a fixed value larger
than it could get in normal useGrid
,
DockPanel
, etc)My problem was that I had ScrollViewer.CanContentScroll="False"
set on my DataGrid. This disables virtualization all together for the DataGrid. More info about this can be found here:
https://stackoverflow.com/a/3724695/4383302