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

前端 未结 12 1468
走了就别回头了
走了就别回头了 2020-11-22 16:19

I want to be able to add a range and get updated for the entire bulk.

I also want to be able to cancel the action before it\'s done (i.e. collection changing besides

12条回答
  •  广开言路
    2020-11-22 16:51

    You can also use this code to extend ObservableCollection:

    public static class ObservableCollectionExtend
    {
        public static void AddRange(this ObservableCollection source, IEnumerable items)
        {
            foreach (var item in items)
            {
                source.Add(item);
            }
        }
    }
    

    Then you don't need to change class in existing code.

提交回复
热议问题