WPF datagrid takes a long time to load
06-Jun-1414 Leave a comment
Scenario
myDataGrid is in a simple WPF Grid control where a RowDefinition has a Height=”*”
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height=”*” />
</Grid.RowDefinitions>
And if myDataTable has a large row count then the following may ‘hang’ or take a long time to load on following code:
myDataGrid.ItemsSource = myDataTable.DefaultView
The issue is that if the DataGrid is in a control that has unlimited height then it will render the whole DataGrid.
Solution
Options to resolve this include:
- Changing the RowDefinition Height
- Add MaxHeight to the DataGrid, so <DataGrid x:Name=”myDataGrid” MaxHeight=”1000″ />
Performance is then fine.
With thanks to: http://stackoverflow.com/questions/3336921/unreasonable-wpf-datagrid-loading-time
End.