本文整理汇总了C#中DelegateCommand.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.CanExecute方法的具体用法?C# DelegateCommand.CanExecute怎么用?C# DelegateCommand.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DelegateCommand
的用法示例。
在下文中一共展示了DelegateCommand.CanExecute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RaiseCanExecuteChangedTest
public void RaiseCanExecuteChangedTest()
{
var executed = false;
var canExecute = false;
var command = new DelegateCommand(() => executed = true, () => canExecute);
Assert.IsFalse(command.CanExecute(null));
canExecute = true;
Assert.IsTrue(command.CanExecute(null));
AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());
Assert.IsFalse(executed);
}
示例2: ExecuteTest3
public void ExecuteTest3()
{
var executed = false;
var canExecute = true;
var command = new DelegateCommand(() => executed = true, () => canExecute);
Assert.IsTrue(command.CanExecute(null));
command.Execute(null);
Assert.IsTrue(executed);
executed = false;
canExecute = false;
Assert.IsFalse(command.CanExecute(null));
command.Execute(null);
Assert.IsFalse(executed);
}
示例3: WhenCanExecuteParameterIsNull_ThenExecutes
public void WhenCanExecuteParameterIsNull_ThenExecutes()
{
var command = new DelegateCommand(() => { }, () => true);
var can = command.CanExecute(null);
Assert.True(can);
}
示例4: ExecuteNoPredicateWithNull
public void ExecuteNoPredicateWithNull()
{
bool called = false;
DelegateCommand cmd = new DelegateCommand((o) => called = true);
Assert.IsTrue(cmd.CanExecute(null), "Command should always be able to execute when no predicate is supplied.");
cmd.Execute(null);
Assert.IsTrue(called, "Command did not run supplied Action.");
}
示例5: CanExecuteReturnsResultOfTheFunctionIfItWasGiven
public void CanExecuteReturnsResultOfTheFunctionIfItWasGiven()
{
_sut = new DelegateCommand(d => executed = true, d => false);
var result = _sut.CanExecute(null);
Assert.IsFalse(result);
}
示例6: CanExectue_WithoutCanExecute_True
public void CanExectue_WithoutCanExecute_True()
{
var subject = new DelegateCommand(() => { });
var result = subject.CanExecute();
Assert.IsTrue(result);
}
示例7: CanExecute_NoCanExecuteDelegateDefined_ReturnsTrue
public void CanExecute_NoCanExecuteDelegateDefined_ReturnsTrue ()
{
Action<object> execute = delegate { };
var command = new DelegateCommand (execute);
bool result = command.CanExecute (null);
Assert.IsTrue (result);
}
示例8: CanExecuteDelegateWorks
public void CanExecuteDelegateWorks()
{
Predicate<object> predicate = (o) =>
{
if (o is bool)
return (bool)o;
else
return false;
};
Action<object> action = o => { };
bool canExecute = false;
ICommand delegateCommand = new DelegateCommand(action, predicate);
Assert.IsFalse(delegateCommand.CanExecute(canExecute));
canExecute = true;
Assert.IsTrue(delegateCommand.CanExecute(canExecute));
}
示例9: CanExecute
public void CanExecute()
{
bool b = false;
int i = 0;
Action<int> execute = (param => i = i + param);
Func<int, bool> predicate = (param => b);
var command = new DelegateCommand<int>(execute, predicate);
Assert.IsFalse(((ICommand)command).CanExecute(i));
Assert.IsFalse(command.CanExecute(i));
b = true;
Assert.IsTrue(((ICommand)command).CanExecute(i));
Assert.IsTrue(command.CanExecute(i));
b = false;
Assert.IsFalse(((ICommand)command).CanExecute(i));
Assert.IsFalse(command.CanExecute(i));
}
示例10: ExecuteTest2
public void ExecuteTest2()
{
var executed = false;
object commandParameter = null;
var command = new DelegateCommand(parameter =>
{
executed = true;
commandParameter = parameter;
});
var obj = new object();
Assert.IsTrue(command.CanExecute(null));
Assert.IsTrue(command.CanExecute(obj));
command.Execute(obj);
Assert.IsTrue(executed);
Assert.AreSame(obj, commandParameter);
}
示例11: CanExecuteReturnsTrueWithouthCanExecuteDelegate
public void CanExecuteReturnsTrueWithouthCanExecuteDelegate()
{
var handlers = new DelegateHandlers();
var command = new DelegateCommand<object>(handlers.Execute);
bool retVal = command.CanExecute(null);
Assert.AreEqual(true, retVal);
}
示例12: CanExecute
public void CanExecute()
{
bool b = false;
int i = 0;
Action execute = (() => i++);
Func<bool> predicate = (() => b);
var command = new DelegateCommand(execute, predicate);
object dummy = new object();
Assert.IsFalse(((ICommand)command).CanExecute(dummy));
Assert.IsFalse(command.CanExecute());
b = true;
Assert.IsTrue(((ICommand)command).CanExecute(dummy));
Assert.IsTrue(command.CanExecute());
b = false;
Assert.IsFalse(((ICommand)command).CanExecute(dummy));
Assert.IsFalse(command.CanExecute());
}
示例13: CanExecute_CanExecuteDelegateDefinedToReturnFalse_ReturnsFalse
public void CanExecute_CanExecuteDelegateDefinedToReturnFalse_ReturnsFalse()
{
Action<object> execute = delegate { };
Predicate<object> canExecute = delegate { return false; };
var command = new DelegateCommand(execute, canExecute);
bool result = command.CanExecute(null);
Assert.IsFalse(result);
}
示例14: ShouldReturnTrueIfConstructedWithNull
public void ShouldReturnTrueIfConstructedWithNull()
{
bool methodCalled = false;
DelegateCommand testCommand = new DelegateCommand((param) => methodCalled = true);
testCommand.Execute(null);
Assert.IsTrue(methodCalled);
Assert.IsTrue(testCommand.CanExecute(null));
}
示例15: CanExecuteCallsPassedInCanExecuteDelegate
public void CanExecuteCallsPassedInCanExecuteDelegate()
{
var handlers = new DelegateHandlers();
var command = new DelegateCommand<object>(handlers.Execute, handlers.CanExecute);
object parameter = new object();
handlers.CanExecuteReturnValue = true;
bool retVal = command.CanExecute(parameter);
Assert.AreSame(parameter, handlers.CanExecuteParameter);
Assert.AreEqual(handlers.CanExecuteReturnValue, retVal);
}