Adding a contents of a List to ObservableCollection


  • Hi,

    I want to add the contents of a List to an ObservableCollection and have found the follow implementation of an AddRange to do this:

    public static class Extensions
       public static void AddRange<T>(this ObservableCollection<T> observableCollection, IList<T> list)
           foreach(var item in list)

    And I call the method like below where observableCollection is a defined as ObservableCollection<string> and list is a List<string>...


    This actually works fine and ultimately does what I need.  However, my problem is that the CollectionChanged event of the ObservableCollection gets fired with the addition of a new item in the AddRange implmentation.

    Is there any way to Add a List of items to an ObservableCollection whereby the CollectionChanged event will only be fired once with e.NewItems containing all the new items.  (instead of the event firing each time with e.NewItems containing one item)

    Thanks for your help on this.


Все ответы