WPF DataGrid 绑定性能问题
我的数据网格有许多以编程方式添加的列。
dgData.Columns.Add(new DataGridTextColumn { Width=50, Header = e.Naam, Binding = new Binding(String.Format("Figures[{0}]", e.Id)) });
设置为数据网格的项目源的集合是数据项的集合
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; }
}
}
当我将集合设置为项目源时,数据网格需要很长时间才能填充数据,有时(大约 25 列)最多可达 30秒或更长时间!
我的 XAML 非常干净:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Name="dgData">
<DataGrid.Columns>
<DataGridTextColumn Header="Set" Binding="{Binding Set}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
是否有任何技巧可以提高此绑定的性能? 如果我在创建列时删除绑定,它执行正常!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试将
EnableColumnsVirtualization
和EnableRowVirtualization
属性设置为 true,至少这会提高填充性能,但滚动仍然会很慢。Please try setting both
EnableColumnsVirtualization
andEnableRowVirtualization
properties to true, at least this will improve population performance, though scrolling still will be slow.