From f3fdd86a0324a04c920d1a3af9a966f38051d51b Mon Sep 17 00:00:00 2001 From: Antony Male Date: Wed, 12 Mar 2014 12:13:15 +0000 Subject: [PATCH] Document BindableCollection --- Stylet/BindableCollection.cs | 37 ++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Stylet/BindableCollection.cs b/Stylet/BindableCollection.cs index b0923da..8f08f59 100644 --- a/Stylet/BindableCollection.cs +++ b/Stylet/BindableCollection.cs @@ -10,25 +10,39 @@ using System.Threading.Tasks; namespace Stylet { + /// + /// Represents a collection which is observasble + /// + /// public interface IObservableCollection : IList, INotifyPropertyChanged, INotifyCollectionChanged { + /// + /// Add a range of items + /// + /// Items to add void AddRange(IEnumerable items); + + /// + /// Remove a range of items + /// + /// Items to remove void RemoveRange(IEnumerable items); } + /// + /// ObservableCollection subclass which supports AddRange and RemoveRange + /// + /// public class BindableCollection : ObservableCollection, IObservableCollection { + /// + /// We have to disable notifications when adding individual elements in the AddRange and RemoveRange implementations + /// private bool isNotifying = true; public BindableCollection() : base() { } public BindableCollection(IEnumerable collection) : base(collection) { } - protected void NotifyOfPropertyChange([CallerMemberName] string propertyName = "") - { - if (this.isNotifying) - this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); - } - protected override void OnPropertyChanged(PropertyChangedEventArgs e) { if (this.isNotifying) @@ -41,6 +55,10 @@ namespace Stylet base.OnCollectionChanged(e); } + /// + /// Add a range of items + /// + /// Items to add public virtual void AddRange(IEnumerable items) { var previousNotificationSetting = this.isNotifying; @@ -57,6 +75,10 @@ namespace Stylet this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items.ToList())); } + /// + /// Remove a range of items + /// + /// Items to remove public virtual void RemoveRange(IEnumerable items) { var previousNotificationSetting = this.isNotifying; @@ -75,6 +97,9 @@ namespace Stylet this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items.ToList())); } + /// + /// Raise a change notification indicating that all bindings should be refreshed + /// public void Refresh() { this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));