开发者

WPF DataGrid performance and selective rendering

开发者 https://www.devze.com 2023-02-19 13:43 出处:网络
I am binding a DataGrid to a dynamic DataSet (db table lookup data) This works fine in most cases, accept when columns store a large information set. One such example is XML type columns that store a

I am binding a DataGrid to a dynamic DataSet (db table lookup data)

This works fine in most cases, accept when columns store a large information set. One such example is XML type columns that store a fairly big snippet of XML configuration data.

In such a case, the grid slows down to a crawl, even when column width/height is constrained to only show the first 300 characters of data in that c开发者_开发技巧ell.

So it seems like the grid renders all of the data in the cell and not just the visible portion.

Is there a way to configure DataGrid to only render sub portion of such cells in a generic way (as i cannot anticipate which columns will need this) ?


It may be unrelated but I had all kinds of problems 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)


Try wrapping your cell's content in a ScrollViewer or something that enables virtualization but has disabled scrollbars.

An alternative is to only return the first 300 characters of your data source

0

精彩评论

暂无评论...
验证码 换一张
取 消