mirror of https://github.com/AMT-Cheif/Stylet.git
Document BindableCollection
This commit is contained in:
parent
70010884a3
commit
f3fdd86a03
|
@ -10,25 +10,39 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Stylet
|
namespace Stylet
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection which is observasble
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
public interface IObservableCollection<T> : IList<T>, INotifyPropertyChanged, INotifyCollectionChanged
|
public interface IObservableCollection<T> : IList<T>, INotifyPropertyChanged, INotifyCollectionChanged
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Add a range of items
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">Items to add</param>
|
||||||
void AddRange(IEnumerable<T> items);
|
void AddRange(IEnumerable<T> items);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a range of items
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">Items to remove</param>
|
||||||
void RemoveRange(IEnumerable<T> items);
|
void RemoveRange(IEnumerable<T> items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ObservableCollection subclass which supports AddRange and RemoveRange
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
public class BindableCollection<T> : ObservableCollection<T>, IObservableCollection<T>
|
public class BindableCollection<T> : ObservableCollection<T>, IObservableCollection<T>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// We have to disable notifications when adding individual elements in the AddRange and RemoveRange implementations
|
||||||
|
/// </summary>
|
||||||
private bool isNotifying = true;
|
private bool isNotifying = true;
|
||||||
|
|
||||||
public BindableCollection() : base() { }
|
public BindableCollection() : base() { }
|
||||||
public BindableCollection(IEnumerable<T> collection) : base(collection) { }
|
public BindableCollection(IEnumerable<T> collection) : base(collection) { }
|
||||||
|
|
||||||
protected void NotifyOfPropertyChange([CallerMemberName] string propertyName = "")
|
|
||||||
{
|
|
||||||
if (this.isNotifying)
|
|
||||||
this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (this.isNotifying)
|
if (this.isNotifying)
|
||||||
|
@ -41,6 +55,10 @@ namespace Stylet
|
||||||
base.OnCollectionChanged(e);
|
base.OnCollectionChanged(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a range of items
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">Items to add</param>
|
||||||
public virtual void AddRange(IEnumerable<T> items)
|
public virtual void AddRange(IEnumerable<T> items)
|
||||||
{
|
{
|
||||||
var previousNotificationSetting = this.isNotifying;
|
var previousNotificationSetting = this.isNotifying;
|
||||||
|
@ -57,6 +75,10 @@ namespace Stylet
|
||||||
this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items.ToList()));
|
this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items.ToList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a range of items
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">Items to remove</param>
|
||||||
public virtual void RemoveRange(IEnumerable<T> items)
|
public virtual void RemoveRange(IEnumerable<T> items)
|
||||||
{
|
{
|
||||||
var previousNotificationSetting = this.isNotifying;
|
var previousNotificationSetting = this.isNotifying;
|
||||||
|
@ -75,6 +97,9 @@ namespace Stylet
|
||||||
this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items.ToList()));
|
this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items.ToList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raise a change notification indicating that all bindings should be refreshed
|
||||||
|
/// </summary>
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
||||||
|
|
Loading…
Reference in New Issue