WPF DataGrid Binding Performance Issue
My datagrid has a number of programmatically added columns.
dgData.Columns.Add(new DataGridTextColumn { Width=50, Header = e.Naam, Binding = new Binding(String.Format("Figures[{0}]", e.Id)) });
The collection th开发者_运维技巧at is set to the item source of the data grid is an collection of Data items
public class Data
{
private string _set = "";
public string Set
{
get { return _set; }
set { _set = value; }
}
private Dictionary<long, int> _figures;
public Dictionary<long, int> Figures
{
get { return _figures; }
set { _figures = value; }
}
}
When I set the collection to the itemssource, it takes ages before the datagrid has been populated with data, sometimes (with about 25 columns) up to 30 seconds or more!
My XAML is pretty clean:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Name="dgData">
<DataGrid.Columns>
<DataGridTextColumn Header="Set" Binding="{Binding Set}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
Are there any tips to improve the performance of this binding? If I remove the binding, at column creation, it performs okay!
Please try setting both EnableColumnsVirtualization
and EnableRowVirtualization
properties to true, at least this will improve population performance, though scrolling still will be slow.
精彩评论