Why does ObservableCollection not support bulk changes?

前端 未结 4 1474
挽巷
挽巷 2021-01-11 14:48

What are the potential problems caused by an ObservableCollection supporting operations like AddRange or RemoveRange? There must be a

4条回答
  •  星月不相逢
    2021-01-11 15:07

    There are numerous extensions to ObservableCollection that can be found on the internet that add the concept of add / remove range, or allow you to defer updates and fire them manually. For example see this Stack Overflow question:

    ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging?

    You can also implement a bulk add that fires a reset event, which will cause the UI to re-render all of the items in the collection:

    http://peteohanlon.wordpress.com/2008/10/22/bulk-loading-in-observablecollection/

    These allow you to more efficiently manage the UI updates. How an ItemsControl handles a collection changed event which details a list of changed items is up to the WPF framework itself. I am assuming it handles this intelligently!

    My advice to you is, if performance is critical to you and you have collections with numerous items being updated and are experiencing performance problem, then subclass ObservableCollection to manage collection changed notification in a manner that best fits your application's needs.

提交回复
热议问题