简体   繁体   English

WPF DataGrid 绑定性能问题

[英]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!当我将集合设置为 itemssource 时,datagrid 需要很长时间才能填充数据,有时(大约 25 列)长达 30 秒或更长时间!

My XAML is pretty clean:我的 XAML 非常干净:

<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.请尝试将EnableColumnsVirtualizationEnableRowVirtualization属性都设置为 true,至少这会提高填充性能,尽管滚动仍然会很慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM