public void ToggleTestCommand(object param) { Console.WriteLine("Clicked! {0}", IsRunning); if (IsRunning && !WantStop) { DispatchNotifySetProperty(() => WantStop, true); } else { DispatchNotifySetProperty(() => WantStop, false); task = new Thread(new ThreadStart(BackgroundTask)); task.Start(); } DispatchNotifySetProperty(() => ToggleTestButtonText, null); Dispatcher.BeginInvoke(new Action(delegate { TestCommand.NotifyCanExecuteChanged(); })); }
public void NotifyCanExecuteChanged_FiresCanExecuteChangedEvent() { MockCommandHandler <MockArgumentClass> handler = new MockCommandHandler <MockArgumentClass>(); DelegateCommand <MockArgumentClass> command = new DelegateCommand <MockArgumentClass>(handler.Execute, handler.CanExecute); int canExecuteChangedCount = 0; command.CanExecuteChanged += (sender, e) => { canExecuteChangedCount++; }; command.NotifyCanExecuteChanged(); Assert.Equal(1, canExecuteChangedCount); }
public void NotifyCanExecuteChangedを呼び出すとCanExecuteChangedイベントが発火される() { var delegateCommand = new DelegateCommand((parameter) => { return(true); }, (parameter) => { }); bool eventFired = false; delegateCommand.CanExecuteChanged += (object sender, EventArgs e) => { Assert.AreSame(delegateCommand, sender); Assert.AreEqual(EventArgs.Empty, e); eventFired = true; }; delegateCommand.NotifyCanExecuteChanged(); Assert.IsTrue(eventFired); }