Smooth scrolling for WPF DataGrid

Viewed 16719

I am using WPF datagrid, only modification I have in place is:

    <toolkit:DataGridTextColumn.ElementStyle>
       <Style TargetType="TextBlock">
       <Setter Property="TextWrapping" Value="Wrap"/>
      </Style>
    </toolkit:DataGridTextColumn.ElementStyle>

I have this modification so if the cell contents are longer, they stretch the line height, no text is hidden. Problem is with DataGrid's scrolling behaviour - it jumps whole lines when scrolling, which does not work well at all if the row is higher than one line - scrollbar is jerking on scrolling etc.

Is there any way to make WPF DataGrid scroll "smoothly" and not line by line?

Thanks

4 Answers

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).

Related