System.Waf.Applications.AsyncDelegateCommand.CanExecute C# (CSharp) Метод

CanExecute() публичный Метод

Defines the method that determines whether the command can execute in its current state.
public CanExecute ( object parameter ) : bool
parameter object Data used by the command. If the command does not require data to be passed, this object can be set to null.
Результат bool
        public bool CanExecute(object parameter)
        {
            return !IsExecuting && (canExecute == null || canExecute(parameter));
        }

Usage Example

Пример #1
0
        public void CanExecuteDuringAsyncExecute2()
        {
            var tcs = new TaskCompletionSource<object>();
            var canExecute = false;
            var executeCalled = false;

            var command = new AsyncDelegateCommand(() =>
            {
                executeCalled = true;
                return tcs.Task;
            }, () => canExecute);

            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);

            executeCalled = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            tcs.SetResult(null);
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executeCalled);
        }
All Usage Examples Of System.Waf.Applications.AsyncDelegateCommand::CanExecute