private void OnFavoriteItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (PlaylistItem item in e.NewItems) { FavoriteChanged?.Invoke( this, new FavoriteChangedEventArgs { Change = FavoriteChangeType.Added, Item = item }); } break; case NotifyCollectionChangedAction.Remove: foreach (PlaylistItem item in e.OldItems) { FavoriteChanged?.Invoke( this, new FavoriteChangedEventArgs { Change = FavoriteChangeType.Removed, Item = item }); } break; } }
private void ReplaceFavoriteList(Playlist newList) { FavoriteList.Items.CollectionChanged -= OnFavoriteItemsChanged; newList.Items.CollectionChanged += OnFavoriteItemsChanged; _playlists[_favoriteListName] = newList; FavoriteChanged?.Invoke(this, new FavoriteChangedEventArgs { Change = FavoriteChangeType.Unknown }); }
protected void ckShowInFavorites_CheckedChanged(object sender, EventArgs e) { CheckBox ck = (CheckBox)sender; Aircraft ac = RowFromControl(ck); ac.HideFromSelection = !ck.Checked; UserAircraft ua = new UserAircraft(Page.User.Identity.Name); ua.FAddAircraftForUser(ac); FavoriteChanged?.Invoke(this, e); }
public async Task RemoveListAsync(string name) { using (await _syncRoot.LockAsync()) { if (name == _favoriteListName) { FavoriteList.Items.Clear(); await AddOrUpdatePlaylist(FavoriteList); PlaylistChanged?.Invoke(this, new PlaylistChangedEventArgs { Action = PlaylistChangeAction.Content, NewTitle = name, Playlist = FavoriteList, }); FavoriteChanged?.Invoke(this, new FavoriteChangedEventArgs { Change = FavoriteChangeType.Unknown }); } else { PlaylistChanged?.Invoke(this, new PlaylistChangedEventArgs { Action = PlaylistChangeAction.Remove, OldTitle = name, Playlist = _playlists[name], }); await Task.Run(() => { File.Delete(_nameToPathMap[name]); _nameToPathMap.Remove(name); _playlists.Remove(name); }); } } }