Exemplo n.º 1
0
        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            // Add to playlist
            var menuItem = (MenuItem)sender;

            var contextMenu = (ContextMenu)menuItem.Parent;
            var row         = (DataGrid)contextMenu.PlacementTarget;
            var item        = (KnownSongInfo)row.SelectedCells[0].Item;
            var playlist    = _mainPlaylistData.FirstOrDefault(p => Equals(p.Value.AssociatedContextItem, menuItem)).Key;

            if (playlist == null)
            {
                MessageBox.Show("Error while looking for playlist.");
                return;
            }

            var songData = new SavedSong()
            {
                Artist = item.Artist,
                Name   = item.Name,
                Uri    = item.GetSong().Uri,
            };


            var data = PlaylistSaver.Data.First(p => p.Equals(playlist));

            if (data.Songs == null)
            {
                data.Songs = new List <SavedSong> {
                    songData
                }
            }
            ;
            else
            {
                data.Songs.Add(songData);
            }
            PlaylistSaver.SaveAll();
        }
Exemplo n.º 2
0
        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            // Add to playlist
            var menuItem = (MenuItem) sender;

            var contextMenu = (ContextMenu) menuItem.Parent;
            var row = (DataGrid)contextMenu.PlacementTarget;
            var item = (KnownSongInfo)row.SelectedCells[0].Item;
            var playlist = _mainPlaylistData.FirstOrDefault(p => Equals(p.Value.AssociatedContextItem, menuItem)).Key;
            if (playlist == null)
            {
                MessageBox.Show("Error while looking for playlist.");
                return;
            }

            var songData = new SavedSong()
            {
                Artist = item.Artist,
                Name = item.Name,
                Uri = item.GetSong().Uri,
            };

            var data = PlaylistSaver.Data.First(p => p.Equals(playlist));
            if(data.Songs == null)
                data.Songs = new List<SavedSong> {songData};
            else
                data.Songs.Add(songData);
            PlaylistSaver.SaveAll();
        }