简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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