Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After our conversation above, this is rather moot, but I thought about how I'd implement a base class that fired PropertyChanged events when a collection changed in a property that was defined by the subclass. As I said, it's a bit non-standard, but here's how I'd do it.</p> <pre><code>class FancyCollectionAndPropertyChangedBase : INotifyPropertyChanged { private Dictionary&lt;ICollectionChanged, String&gt; collectionNameLookup = new Dictionary&lt;ICollectionChanged, String&gt;(); protected FancyCollectionAndPropertyChangedBase() { this.PropertyChanged += MyPropertyChanged; } private void MyPropertyChanged(object sender, PropertyChangedEventArgs e) { if(this.collectionNameLookup.ContainsValue(e.PropertyName) { KeyValuePair&lt;INotifyCollectionChanged, String&gt; oldValue = this.collectionNameLookup.First(kvp =&gt; kvp.Value == e.Name); oldValue.Key -= MyCollectionChanged; this.collecitonNameLookup.Remove(oldValue.Key); INotifyCollectionChanged collection = this.GetType().GetProperty(e.PropertyName, BindingFlags.FlattenHierarchy).GetValue(this, null); collection.CollectionChanged += MyCollectionChanged; this.collectionNameLookup.Add(collection, e.Name); } else if(typeof(INotifyCollectionChanged).IsAssignableFrom(this.GetType().GetProperty(e.PropertyName, BindingFlags.FlattenHierarchy).PropertyType)) { // Note: I may have gotten the IsAssignableFrom statement, above, backwards. INotifyCollectionChanged collection = this.GetType().GetProperty(e.PropertyName, BindingFlags.FlattenHierarchy).GetValue(this, null); collection.CollectionChanged += MyCollectionChanged; this.collectionNameLookup.Add(collection, e.Name); } } private void MyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { this.NotifyPropertyChanged(this.collectionNameLookup[sender]; } } </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