Smooth scrolling for WPF DataGrid Smooth scrolling for WPF DataGrid wpf wpf

Smooth scrolling for WPF DataGrid


I haven't played with the DataGrid explicitly, but it is factual that using ScrollViewer.CanContentScroll=False swaps out the default ItemsPanelTemplate which uses the VirtualizedStackPanel with a regular StackPanel. It will scroll smoothly, but it will be rendering every item even if it's not visible.

This can absolutely kill performance if you're dealing with either a complex visual tree or large datasets.


The DataGrid has an Attached property, ScrollViewer.CanContentScroll, that manages this behavior. To get smooth scrolling you'll need to set it to False.


Use this:

<DataGrid VirtualizingPanel.ScrollUnit="Pixel">

Dont use CanContentScroll="False". It disables virtualisation, which can causes long loading times when you have a lot of rows. Virtualisation means it will only render the data that is shown and not all the data of the datagrid.

But disabling virutalisation may help when you have not too much rows, but each row is complex to create (complex datatemplates/controls, a lot of data etc. in each row).