Wednesday 19 June 2013

Slow WPF DataGrid when Grouping Styles Added

I found while working a project recently, that when I added the styling for Grouping, even if I wasn’t actually using it, that the load time for my data was massively affected.

Evidently, the reason or this slow down is due to the fact that, unbeknown to me, when grouping is enabled in WPF, then Virtualisation is disabled by default.

Virtualisation allows WPF to not physically render items which don’t appear directly in the UI, thus it doesn’t need to perform all the complicated UI math related to showing UI elements. This vastly improves performance, in my case, when dealing with Data Sources which have rows exceeding a few hundred.

Thankfully, WPF and .Net 4.5 has enabled a way for Virtualisation to be re-enabled when grouping. Simply adding the following to the Datagrid re-enabled Virtualisation.

   1: VirtualizingStackPanel.IsVirtualizing="True”

No comments:

Post a Comment