Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth scrolling for WPF DataGrid

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


1 Answers

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.

like image 160
erodewald Avatar answered Sep 13 '25 13:09

erodewald