Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve WPF DataGrid performance

In my .NET 3.5 WPF Application, I have a WPF DataGrid which will be populated with 500 columns and 50 rows. The performance of App is very very poor in scrolling, or when I do DataGrid.Items.Refresh() or in selecting rows.

Actually App will take around 20 sec to Update Layout. Layout_Updated() event will trigger after 20 sec.

If I reduce the columns to 50 or less, App will be very responsive. As per my findings performance is directly related to column count.

How do I improve the DataGrid performance?

like image 852
Kishor Avatar asked Dec 07 '12 14:12

Kishor


1 Answers

There are a few options you can turn on to help you on your DataGrid object

EnableColumnVirtualization = true EnableRowVirtualization = true 

These two are the main ones I think might help. Next try making your binding async

ItemsSource="{Binding MyStuff, IsAsync=True}" 

And lastly, I've heard that setting a maximum height and width can help even if it above the max screen size, but I didn't notice a difference myself (claim had to do with auto size measuring)

MaxWidth="2560" MaxHeight="1600" 

Also never put a DataGrid in a ScrollViewer, because you will essentially lose virtualization. Let me know if this helps!

like image 107
Alan Avatar answered Oct 04 '22 15:10

Alan