示例#1
0
        private async void AllMusic_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                MusicCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                // ArtistCollection.AddRange(e.NewItems.Cast<LocalMusic>());
                AlbumCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (LocalMusic item in e.OldItems)
                {
                    MusicCollection.Remove(item);
                    //  ArtistCollection.Remove(item);
                    AlbumCollection.Remove(item);
                }
                await ArtistCollection.AddRangeAsync(AllMusic.GroupBy(x => x.ArtistsName?.FirstOrDefault() ?? "未知艺术家").ToDictionary(x => x.Key, x => x.ToArray())
                                                     .Select(x =>
                                                             new LocalArtist
                {
                    Name        = x.Key,
                    PicPath     = x.Value.First().Id3Pic,
                    LocalMusics = x.Value
                }));

                break;

            case NotifyCollectionChangedAction.Replace:
                break;

            case NotifyCollectionChangedAction.Move:
                break;

            case NotifyCollectionChangedAction.Reset:
                MusicCollection.Clear();
                ArtistCollection.Clear();
                AlbumCollection.Clear();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public void Dispose()
 {
     AlbumCollection.Clear();
 }