private static void Compute_CollectionChanged(ISelectionableControl lb, IList l, NotifyCollectionChangedEventArgs e) { if (l == null) return; if (e.Action == NotifyCollectionChangedAction.Reset) { lb.SelectedItems.Clear(); InitCollection(l, lb); return; } if (e.NewItems != null) { e.NewItems.Cast<object>().Apply(o => lb.SelectedItems.Add(o)); } if (e.OldItems != null) { e.OldItems.Cast<object>().Apply(o => lb.SelectedItems.Remove(o)); } }
private static void RegisterIfPossible(IList ientry, ISelectionableControl icontainer) { INotifyCollectionChanged inc = ientry as INotifyCollectionChanged; if (inc != null) { HashSet<ISelectionableControl> listeners = null; if (!_Mapped.TryGetValue(inc, out listeners)) { listeners = new HashSet<ISelectionableControl>(); _Mapped.Add(inc, listeners); inc.CollectionChanged += inc_CollectionChanged; } listeners.Add(icontainer); } }
private static void UnregisterIfPossible(IList ientry, ISelectionableControl icontainer) { INotifyCollectionChanged inc = ientry as INotifyCollectionChanged; if (inc != null) { HashSet<ISelectionableControl> listeners = _Mapped[inc]; listeners.Remove(icontainer); if (listeners.Count==0) { _Mapped.Remove(inc); inc.CollectionChanged -= inc_CollectionChanged; } } }
private static void InitCollection(IList ilis, ISelectionableControl lb) { ilis.Cast<object>().Apply(o => lb.SelectedItems.Add(o)); }