Example #1
0
        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();
            }
        }
Example #2
0
 private void RecreateCombinedResults()
 {
     CombinedResults.Clear();
     foreach (Source source in this)
     {
         foreach (AlbumArt albumArt in source.Results)
         {
             CombinedResults.Add(albumArt);
         }
     }
 }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
            }
        }