Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Toolkit DataGrid scrolling performance problems - why?

Tags:

I have a performance problem with the (WPF Toolkit) DataGrid. It contains about 1.000 rows (only eight columns) and scrolling is horribly slow and laggy. Also the initial load of the Window containing the DataGrid takes 5-10 seconds.

I did some research (using google and StackOverflow) but couldn't find anything besides the advice to turn on UI virtualization. But even after explictly enabling that scrolling continues to be awfully slow.

My DataGrid is bound to an ICollectionView / CollectionViewSource. It's is defined in XAML like this (the columns are explicitly defined, not auto generated):

    <tk:DataGrid x:Name="dataGrid" 
                 ItemsSource="{Binding Path=Bookings}" 
                 AutoGenerateColumns="False" 
                 Grid.Row="1" 
                 EnableRowVirtualization="True" 
                 EnableColumnVirtualization="True"
                 VirtualizingStackPanel.IsVirtualizing="True"
                 VirtualizingStackPanel.VirtualizationMode="Recycling">
            ... 
    </tk:DataGrid>

The DataContext for the entire Window is set to an instance of the class containing the ICollectionView the DataGrid is bound to.

Every blog or forum post I found was praising the DataGrid's performance so I'm quite obviously doing something seriously wrong. Since I'm quite new to WPF in general and especially to the DataGrid I've no clue of how to improve this. Does anybody have some advice for me? What's your experience with the DataGrid? What am I doing wrong?

Edit: Just followed this question's advice to set the Width of all columns to "Auto". That did not change the bad scrolling performance. Also I'm not using DataGridTemplateColumns (just some DataGridTextColumns and two DataGridComboBoxColumns).

Edit2: I used Snoop to look at my app. What I see suggests that virtualization is indeed working (only 19 rows, not a thousand). But every row contains 52 elements, so those add up to more than thousand elements. Might that be a / the problem?

Thanks a lot!

like image 239
andyp Avatar asked Nov 09 '09 22:11

andyp


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

like image 60
Ali Pourheidar Avatar answered Sep 23 '22 13:09

Ali Pourheidar


After finally making the time to build my application against an up-to-date version of WPF the scrolling problem seems completely gone. So if anyone still uses the toolkit version of the DataGrid just "update" to the version included in the framework and you should be fine.

like image 33
andyp Avatar answered Sep 23 '22 13:09

andyp


I am using .NET 4.0 and still get the scroll performance problem. What I did is - disabled virtualization. I set EnableRowVirtualization to 'false' in the DataGrid. This considerably improved the scroll performance.

I would suggest to not assume that whatever is being offered by WPF is useful in all the situations.

like image 32
thewpfguy Avatar answered Sep 25 '22 13:09

thewpfguy