mirror of
https://github.com/4sval/FModel.git
synced 2026-06-21 15:30:05 -05:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
|
|
namespace FModel.Framework;
|
|
|
|
public sealed class RangeObservableCollection<T> : ObservableCollection<T>
|
|
{
|
|
private bool _suppressNotification;
|
|
|
|
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
|
{
|
|
if (!_suppressNotification)
|
|
base.OnCollectionChanged(e);
|
|
}
|
|
|
|
public void AddRange(IEnumerable<T> list)
|
|
{
|
|
if (list == null)
|
|
throw new ArgumentNullException(nameof(list));
|
|
|
|
_suppressNotification = true;
|
|
|
|
foreach (var item in list)
|
|
Add(item);
|
|
|
|
_suppressNotification = false;
|
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
}
|
|
|
|
public void SetSuppressionState(bool state)
|
|
{
|
|
_suppressNotification = state;
|
|
}
|
|
|
|
public void InvokeOnCollectionChanged(NotifyCollectionChangedAction changedAction = NotifyCollectionChangedAction.Reset)
|
|
{
|
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(changedAction));
|
|
}
|
|
} |