public void DelegateCommand_EventTest1() { var eventFired = false; EventHandler foo = (s, e) => eventFired = true; var cmd = new DelegateCommand <string>(x => { }, x => true); cmd.CanExecuteChanged += foo; Assert.IsFalse(eventFired); cmd.OnCanExecuteChanged(); Assert.IsTrue(eventFired); eventFired = false; cmd.CanExecuteChanged -= foo; cmd.OnCanExecuteChanged(); Assert.IsFalse(eventFired); }
public MainViewModel() { ShowSearchCommand = new DelegateCommand(ShowSearch); ShowResultsCommand = new DelegateCommand(ShowResults, p => SearchBookService.LastSearchResult != null); ShowFavoritesCommand = new DelegateCommand(ShowFavorites, p => FavoritesManager.Favorites.Count > 0); SearchBookService.SuccessfulSearch += (aaaa, bbbb) => ShowResultsCommand.OnCanExecuteChanged(); FavoritesManager.FavoritesChanged += (asd, asda) => ShowFavoritesCommand.OnCanExecuteChanged(); }
public void DelegateCommand_EventTest2() { var eventFired = false; EventHandler foo = (s, e) => eventFired = true; var cmd = new DelegateCommand(() => { }, null); cmd.CanExecuteChanged += foo; Assert.IsFalse(eventFired); cmd.OnCanExecuteChanged(); Assert.IsFalse(eventFired); eventFired = false; cmd.CanExecuteChanged -= foo; cmd.OnCanExecuteChanged(); Assert.IsFalse(eventFired); }
private void UpdateStateListCommands() { _Player1ScoredCommand.OnCanExecuteChanged(); _Player1ReducedCommand.OnCanExecuteChanged(); _Player2ScoredCommand.OnCanExecuteChanged(); _Player2ReducedCommand.OnCanExecuteChanged(); _UndoCommand.OnCanExecuteChanged(); OnPropertyChanged("CanToggleIsTieBreakEnabled"); OnPropertyChanged("IsTieBreakEnabled"); }
public MainWindowViewModel() { SuchCommand = new DelegateCommand(async p => { Buchergebnisse = (await BookSearchService.Suche(Suchbegriff)).ToArray(); }, p => !string.IsNullOrWhiteSpace(Suchbegriff)); FavoritenCommand = new DelegateCommand(p => { Header = "Favoriten"; Buchergebnisse = FavoritenManager.Favoriten.ToArray(); }, p => FavoritenManager.Favoriten.Count > 0); AddFavoriteCommand = new DelegateCommand(p => { if (p is Book book) { FavoritenManager.Favoriten.Add(book); FavoritenCommand.OnCanExecuteChanged(); } }); }