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 RecreateCombinedResults() { CombinedResults.Clear(); foreach (Source source in this) { foreach (AlbumArt albumArt in source.Results) { CombinedResults.Add(albumArt); } } }
private void HookSource(Source source) { if (Count == 1) //First item to be inserted { AllEnabled = source.IsEnabled; } else if (AllEnabled.HasValue && AllEnabled.Value != source.IsEnabled) { AllEnabled = null; } source.PropertyChanged += new PropertyChangedEventHandler(OnSourcePropertyChanged); source.Results.CollectionChanged += new NotifyCollectionChangedEventHandler(OnSourceResultsChanged); foreach (AlbumArt albumArt in source.Results) { CombinedResults.Add(albumArt); } }