Hi Greg,
Your right. In the mean time we've cooked up a solution. Below's (part of) our code. We attach to the ListChanged event and act accordingly. This class is base on a class we call the ObservableList<T> which already has an implementation of the OnListChanged event (override). The class uses the RelatedEntityList<T> of DevForce and maintains its own list (that's why there is a RefillList()). The class is build using the principal: 'First make it work, than make it better and than make it fast'. We've proved it works.
Regards,
Paul Sinnema
Diartis AG
public override void OnListChanged(object sender, ObservableListChangedEventArgs e) { if (m_SuspendItemChangedEvents == 0) { switch (e.Action) { case ObservableListChangedAction.Add: base.OnListChanged(sender, e); AttachPropertyChangedEvents(e.NewItems); break;
case ObservableListChangedAction.Remove: DetachPropertyChangedEvents(e.OldItems); base.OnListChanged(sender, e); break;
case ObservableListChangedAction.Replace: case ObservableListChangedAction.Move: DetachPropertyChangedEvents(e.OldItems); base.OnListChanged(sender, e); AttachPropertyChangedEvents(e.NewItems); break;
case ObservableListChangedAction.None: case ObservableListChangedAction.Reset: case ObservableListChangedAction.Resync: base.OnListChanged(sender, e); break;
default: throw new InvalidArgumentException("e.Action", e.Action); } } }
private void AttachChangedEvents() { if (m_RelatedEntityList != null) { m_RelatedEntityList.CollectionChanged += RelatedEntityListCollectionChanged;
AttachPropertyChangedEvents(m_RelatedEntityList); } }
private void AttachPropertyChangedEvents(IList list) { foreach (T item in list) { item.PropertyChanged += ItemPropertyChanged; } }
private void DetachChangedEvents() { if (m_RelatedEntityList != null) { m_RelatedEntityList.CollectionChanged -= RelatedEntityListCollectionChanged;
DetachPropertyChangedEvents(m_RelatedEntityList); } }
private void DetachPropertyChangedEvents(IList list) { foreach (T item in list) { item.PropertyChanged -= ItemPropertyChanged; } }
private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is T) { int index = IndexOf((T)sender); if (index >= 0) { this.OnItemChanged(sender, new ItemPropertyChangedEventArgs(this, sender, index, e.PropertyName)); }
RefillList(); } }
------------- Senior Developer at Diartis AG in Switzerland.
|