void DeleteFavoriteCommand_Executed(object sender, ExecutedRoutedEventArgs e) { if (LsvFavorites != null && LsvFavorites.SelectedItems.Count > 0) { var result = MessageBox.Show(this, string.Format("Are you sure Delete {0} items?", LsvFavorites.SelectedItems.Count), Title, MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result != MessageBoxResult.OK) { return; } var favs = LsvFavorites.SelectedItems.OfType <Favorite>().ToArray(); foreach (var fav in favs) { Favorites.List.Remove(fav); } try { Favorites.Save(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } } }
void BtnAddFavorite_Click(object sender, RoutedEventArgs e) { if (PopupFavorite.IsOpen && PopupFavorite.DataContext is Favorite) { var fav = (Favorite)PopupFavorite.DataContext; Favorites.List.Add(fav); try { Favorites.Save(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } PopupFavorite.IsOpen = false; PopupFavorite.DataContext = null; } }