Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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();
                }
            });
        }