WPF DataGrid performance concerns

前端 未结 3 1535
刺人心
刺人心 2021-02-04 07:50

I am testing WPF DataGrid in hopes of replacing some winforms controls, and so far have been very pleased with the development process. Performance seems to be my biggest concer

相关标签:
3条回答
  • 2021-02-04 07:53

    You mean DataGrid from WPF Toolkit? If yes, In my opinion it's pretty slow, so I ended up using ListView with GridView.

    0 讨论(0)
  • 2021-02-04 07:55

    More general tips:

    For scrolling, what we have done is tried to use Deferred Scrolling.

    To improve the Filtering performance you could consider filtering the bound collection yourself.

    For grids with large number of columns apply ColumnVirtualization as well. This tends to affect the horizontal scrolling a little bit adversely but you could test your scenario and apply improvements. For us it did work perfectly. It helped us on Refresh, Reload, Render scenarios for large grids.

    Performance is also impacted by the styling applied.

    0 讨论(0)
  • 2021-02-04 08:12

    A general tip for DataGrid performance issues: I had a problem with the DataGrid in which it took literally seconds to refresh after a window resize, column sort, etc. and locked up the window UI while it was doing so (1000 rows, 5 columns).

    It came down to an issue (bug?) with the WPF sizing calculations. I had it in a grid with the RowDefinition Height="Auto" which was causing the rendering system to try and recalculate the size of the DataGrid at runtime by measuring the size of each and every column and row, presumably by filling the whole grid (as I understand it). It is supposed to handle this intelligently somehow but in this case it was not.

    A quick check to see if this is a related problem is to set the Height and Width properties of the DataGrid to a fixed size for the duration of the test, and try running again. If your performance is restored, a permanent fix may be among these options:

    • Change the sizes of the containing elements to be relative (*) or fixed values
    • Set MaxHeight and MaxWidth of the DataGrid to a fixed value larger than it could get in normal use
    • Try another container type with different resizing strategy (Grid, DockPanel, etc)
    0 讨论(0)
提交回复
热议问题