using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; namespace MSFSPopoutPanelManager.Shared { public class ObservableRangeCollection : ObservableCollection { public ObservableRangeCollection() { } public ObservableRangeCollection(IEnumerable collection) : base(collection) { } public void AddRange(IEnumerable collection) { if (collection == null) throw new ArgumentNullException(nameof(collection)); foreach (var i in collection) Items.Add(i); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } public void RemoveRange(IEnumerable collection) { if (collection == null) throw new ArgumentNullException(nameof(collection)); foreach (var i in collection) Items.Remove(i); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } public void Replace(T item) { ReplaceRange(new [] { item }); } public void ReplaceRange(IEnumerable collection) { if (collection == null) throw new ArgumentNullException(nameof(collection)); Items.Clear(); foreach (var i in collection) Items.Add(i); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } } }