本文整理汇总了C#中DelegateCommand.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.Execute方法的具体用法?C# DelegateCommand.Execute怎么用?C# DelegateCommand.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DelegateCommand
的用法示例。
在下文中一共展示了DelegateCommand.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhenNoCanExecuteSpecified_ThenExecutesAlways
public void WhenNoCanExecuteSpecified_ThenExecutesAlways()
{
var executed = 0;
var command = new DelegateCommand(() => executed++);
command.Execute(new object());
command.Execute(new object());
Assert.Equal(2, executed);
}
示例2: Main
static void Main(string[] args)
{
Receiver receiver = new Receiver();
Command command = new ConcreteCommand(receiver);
var results = command.Execute().Results;
Console.WriteLine(results);
bool condition = false;
DelegateCommand delegateCommand = new DelegateCommand(() => Console.WriteLine("Hello World!"), () => condition);
delegateCommand.Execute();
condition = true;
delegateCommand.Execute();
}
示例3: 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);
}
示例4: Execute_should_run_action_with_progress_monitor
public void Execute_should_run_action_with_progress_monitor()
{
var monitor = MockRepository.GenerateStub<IProgressMonitor>();
var command = new DelegateCommand(pm => Assert.AreEqual(monitor, pm));
command.Execute(monitor);
}
示例5: ContactEditorViewModel
public ContactEditorViewModel(ICommandInvoker commandInvoker, IQueryInvoker queryInvoker)
{
this.queryInvoker = queryInvoker;
Contacts = queryInvoker.Query<AllContactsQueryResult>().Contacts;
SaveCommand = new DelegateCommand(() =>
{
if (CurrentContact.Command is UpdateContactCommand)
{
commandInvoker.Execute<UpdateContactCommand, UpdateContactQueryResult>((UpdateContactCommand) CurrentContact.Command);
}
else
{
commandInvoker.Execute<CreateContactCommand, CreateContactQueryResult>(CurrentContact.Command);
}
Contacts = queryInvoker.Query<AllContactsQueryResult>().Contacts;
});
NewCommand = new DelegateCommand(() =>
{
var modifyContactQueryResult = queryInvoker.Query<CreateContactQueryResult>();
CurrentContact = new CreateContactViewModel(modifyContactQueryResult, new ValidationService());
});
NewCommand.Execute(null);
}
示例6: 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.");
}
示例7: ExecuteTest
public void ExecuteTest()
{
bool executed = false;
DelegateCommand command = new DelegateCommand(() => executed = true);
command.Execute(null);
Assert.IsTrue(executed);
}
示例8: ExecuteTest_CanExecute_True
public void ExecuteTest_CanExecute_True()
{
bool executed = false;
bool canExecute = true;
DelegateCommand command = new DelegateCommand(() => executed = true, () => canExecute);
command.Execute();
Assert.IsTrue(executed);
}
示例9: Execute_should_run_action
public void Execute_should_run_action()
{
bool flag = false;
var command = new DelegateCommand(pm => flag = true);
command.Execute(MockRepository.GenerateStub<IProgressMonitor>());
Assert.IsTrue(flag);
}
示例10: WhenExecuteParameterIsNull_ThenExecutes
public void WhenExecuteParameterIsNull_ThenExecutes()
{
var executed = false;
var command = new DelegateCommand(() => executed = true, () => true);
command.Execute(null);
Assert.True(executed);
}
示例11: Execute_WithoutCanExecute__DelegateCalled
public void Execute_WithoutCanExecute__DelegateCalled()
{
var called = false;
var subject = new DelegateCommand(() => { called = true; });
subject.Execute();
Assert.IsTrue(called);
}
示例12: WhenCanExecuteReturnsFalse_ThenDoesNotExecute
public void WhenCanExecuteReturnsFalse_ThenDoesNotExecute()
{
var executed = false;
var command = new DelegateCommand(() => executed = true, () => false);
command.Execute(new object());
Assert.False(executed);
}
示例13: WhenCanExecuteReturnsTrue_ThenExecutes
public void WhenCanExecuteReturnsTrue_ThenExecutes()
{
var executed = false;
var command = new DelegateCommand(() => executed = true, () => true);
command.Execute(new object());
Assert.True(executed);
}
示例14: ExecuteTest4
public void ExecuteTest4()
{
bool executed = false;
bool canExecute = false;
DelegateCommand command = new DelegateCommand(() => executed = true, () => canExecute);
AssertHelper.ExpectedException<InvalidOperationException>(() => command.Execute(null));
Assert.IsFalse(executed);
}
示例15: ExecuteCallsPassedInExecuteDelegate
public void ExecuteCallsPassedInExecuteDelegate()
{
var handlers = new DelegateHandlers();
var command = new DelegateCommand<object>(handlers.Execute, null);
object parameter = new object();
command.Execute(parameter);
Assert.AreSame(parameter, handlers.ExecuteParameter);
}