locked
How to speed up a WPF DataGrid bound to an ObservableCollection? RRS feed

  • Question

  • The application is WPF/MVVM. A DataGrid's ItemSource is bound to an ObservableCollection<LogItem> where LogItem is a plain class of 5 strings and one enumerated value, none of which support the INotifyPropertyChanged interface. The problem is that the time between when the ObservableCollection is updated and when the DataGrid actually displays anything seems excessively long and I'm hoping there's some way to speed this up.

    Here's what I mean. There is a button whose command causes a UserControl to get created. In the UC's associated ViewModel class constructor the ObservableCollection is populated with about 1600 items. The actual population is quick but the UI thread stalls for about 15 seconds which is unexpectedly long. What I suspect is happening is that the DataGrid itself is handling a boat load of notifications from the ObservableCollection and due to sorting and what not it just takes a while.

    On the other hand, I've been using DataGrids for years and haven't ever seen anything this poor in performance before but normally I use a DataTable instead of an ObservableCollection. 


    Richard Lewis Haggard

    Tuesday, June 16, 2020 9:33 PM

All replies

  • Hi,

    Thanks for posting here.

    This forum is for discussing the Windows Desktop Development,

    For wpf issue, you could ask here:

    https://docs.microsoft.com/en-us/answers/topics/wpf.html

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 17, 2020 7:02 AM