private void OnSourceResultsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Replace) { foreach (AlbumArt albumArt in e.NewItems) { CombinedResults.Add(albumArt); } } if (e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Replace) { foreach (AlbumArt albumArt in e.OldItems) { //TODO: Does this need a TryRemoveResultFromCombinedResults helper? CombinedResults.Remove(albumArt); } } //No change needed for move if (e.Action == NotifyCollectionChangedAction.Reset) { //For reset, there is no way of knowing that the items removed are, //so recreate the whole thing RecreateCombinedResults(); } }
private void UnhookSource(Source source) { if (!AllEnabled.HasValue) { //It's possible that all other sources have the same value now RecalculateAllEnabled(); } source.PropertyChanged -= new PropertyChangedEventHandler(OnSourcePropertyChanged); source.Results.CollectionChanged -= new NotifyCollectionChangedEventHandler(OnSourceResultsChanged); foreach (AlbumArt albumArt in source.Results) { CombinedResults.Remove(albumArt); } }