当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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 that 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: