Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>ItemsObservableObservableCollection</h1> <p>The following class is intended to overcome the problem that ObservableCollection does not listen to the changes of the contained objects.</p> <p>The pre-requisite is that the objects which are being added to this collection should implement INotifyPropertyChanged interface.</p> <p>In short, this class registers to the items' PropertyChanged event and rises the CollectionChanged event of the ObservableCollection.</p> <p><a href="http://msdn.microsoft.com/en-us/magazine/dd252944.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/dd252944.aspx</a></p> <pre><code>using System.ComponentModel; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Collections; namespace VJ.Collections { /// &lt;summary&gt; /// This class adds the ability to refresh the list when any property of /// the objects changes in the list which implements the INotifyPropertyChanged. /// /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt; /// The type of elements in the collection. /// &lt;/typeparam&gt; public class ItemsObservableObsrvableCollection&lt;T&gt; : ObservableCollection&lt;T&gt; where T : INotifyPropertyChanged { protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { RegisterPropertyChanged(e.NewItems); } else if (e.Action == NotifyCollectionChangedAction.Remove) { UnRegisterPropertyChanged(e.OldItems); } else if (e.Action == NotifyCollectionChangedAction.Replace) { UnRegisterPropertyChanged(e.OldItems); RegisterPropertyChanged(e.NewItems); } base.OnCollectionChanged(e); } protected override void ClearItems() { UnRegisterPropertyChanged(this); base.ClearItems(); } private void RegisterPropertyChanged(IList items) { foreach (INotifyPropertyChanged item in items) { item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged); } } private void UnRegisterPropertyChanged(IList items) { foreach (INotifyPropertyChanged item in items) { item.PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged); } } private void item_PropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload