Improve Wpf Datagrid Performance

Improve WPF DataGrid performance

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!

WPF Datagrid Performance

Since I can't see your source code it is quite hard to help you. Especially since the performance of a WPF application is influenced by a lot of things. For some hints on what to look out for see Optimizing WPF Application Performance. And yes - it greatly matters what xaml is used in each cell. Because usually performance problems do boil down to "too many elements". Did you know that a TextBox are I think 30 individual elements? I recommend you use the Performance Profiling Tools for WPF to find out more about your specific problem. Try to minimize the amount of elements you are using (e.g. by switching from TextBox to TextBlock where appropriate).

Also you have to check if the performance problems exist on any PC you try the application on. Maybe the PC you are using is forcing WPF into software based rendering. Or are you using any BitmapEffects?

Edit:

Looking at your code I would suggest you change

column.Width = DataGridLength.Auto;

to a reasonable fixed width, since the datagrid does not have to recalculate the width dynamically every time something changes (like adding rows, or even scrolling).

WPF Datagrid VERY SLOW

ALL DataGrid's are horrendously slow (even the ones you pay for). You need to turn on virtualization. VirtualizingStackPanel.IsVirtualizing = true as well as VirtualizingStackPanel.VirtualizationMode = recycling. If you have a lot of columns, or start to do templates, it'll slow to a crawl again. Nothing you can do about that really. I've tried every DataGrid out there (syncfusion, infragistics, etc). They are all very slow.

Slow datagrid - improve performance

In my view, it is not a problem of using IMultiConverter, but Virtualization and Column Rendering.

Try to use these properties to your DataGrid:

  • Enabled VirtualizingStackPanel.VirtualizationMode for a Grid
  • Set VirtualizingStackPanel.IsVirtualizing="true" for DataGrid
  • MaxWidth="2560" MaxHeight="1600"

Never put a DataGrid in a ScrollViewer, because you will essentially lose virtualization.

For example:

<DataGrid ItemsSource="{Binding EmployeeDataTable, IsAsync=True}" 
VirtualizingStackPanel.IsVirtualizing="true" EnableRowVirtualization="True"
EnableColumnVirtualization="True" MaxWidth="2560" MaxHeight="1600"
VirtualizingStackPanel.VirtualizationMode="Recycling"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"/>


Related Topics



Leave a reply



Submit