1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-30 17:50:09 +00:00
msfs-popout-panel-manager/Shared/ObservableRangeCollection.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2024-02-28 02:44:21 +00:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
namespace MSFSPopoutPanelManager.Shared
{
public class ObservableRangeCollection<T> : ObservableCollection<T>
{
public ObservableRangeCollection()
{
}
public ObservableRangeCollection(IEnumerable<T> collection) : base(collection)
{
}
public void AddRange(IEnumerable<T> 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<T> 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<T> collection)
{
if (collection == null) throw new ArgumentNullException(nameof(collection));
Items.Clear();
foreach (var i in collection) Items.Add(i);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
}