本文整理汇总了C#中System.DelegateCommand.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateCommand.Execute方法的具体用法?C# DelegateCommand.Execute怎么用?C# DelegateCommand.Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DelegateCommand
的用法示例。
在下文中一共展示了DelegateCommand.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Updater
private Updater()
{
CheckCommand = new DelegateCommand(async () =>
{
CheckCommand.CanExecute = false;
bool result = await TryFindUpdateAsync();
Status = result ? UpdaterStatus.Download : UpdaterStatus.Check;
if (result && isautoupdate)
{
DispatcherHelper.UIDispatcher.Invoke(() =>
{
if (MessageBox.Show($"{StringTable.Update_Text_Download}{NewVersion}",
StringTable.Update, MessageBoxButton.OKCancel, MessageBoxImage.Information)
== MessageBoxResult.OK)
new AboutWindow { Owner = Application.Current.MainWindow }.ShowDialog();
});
if (Config.Current.AutoDownloadUpdate) DownloadCommand.Execute(null);
else isautoupdate = false;
}
else isautoupdate = false;
CheckCommand.CanExecute = true;
});
DownloadCommand = new DelegateCommand(async () =>
{
Status = UpdaterStatus.CancelDownload;
bool result = await DownloadUpdateAsync();
Status = result ? UpdaterStatus.UpdateFile : UpdaterStatus.Download;
if (result && isautoupdate) UpdateFileCommand.Execute(null);
else isautoupdate = false;
});
CancelDownloadCommand = new DelegateCommand(() =>
{
downloadwebclient?.CancelAsync();
Status = UpdaterStatus.Download;
});
UpdateFileCommand = new DelegateCommand(async () =>
{
UpdateFileCommand.CanExecute = false;
await UpdateFileAsync();
UpdateFileCommand.CanExecute = true;
Status = UpdaterStatus.Restart;
isautoupdate = false;
});
RestartCommand = new DelegateCommand(Restart);
Timer.Elapsed += (_, __) =>
{
if (Status == UpdaterStatus.Check && Config.Current.AutoCheckUpdate)
{
isautoupdate = true;
DispatcherHelper.UIDispatcher.Invoke(() => CheckCommand.Execute(null));
}
};
isautoupdate = true;
CheckCommand.Execute(null);
}
示例2: TestConstructionAndExecute
public async Task TestConstructionAndExecute()
{
bool actioned1 = false;
var command1 = new DelegateCommand<string>((s) => actioned1 = true);
await command1.Execute(null);
Assert.True(actioned1);
Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>((s) => { }, null));
Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>(null, null));
Assert.Throws<ArgumentNullException>(() => new DelegateCommand<string>(null));
bool actioned2 = false;
var command2 = new DelegateCommand<string>((s) =>
{
if (s == "Test")
{
actioned2 = true;
}
});
await command2.Execute("Test");
Assert.True(actioned2);
bool actioned3 = false;
var command3 = new DelegateCommand<string>((s) => actioned3 = true);
await command3.Execute(null);
Assert.True(actioned3);
Assert.Throws<ArgumentNullException>(() => new DelegateCommand(() => { }, null));
Assert.Throws<ArgumentNullException>(() => new DelegateCommand(null, null));
Assert.Throws<ArgumentNullException>(() => new DelegateCommand(null));
}
示例3: ItemListFilterViewModel
public ItemListFilterViewModel(IEventAggregator iEventAggregator, int _numControls)
{
this.iEventAggregator = iEventAggregator;
buttonActions = new string[] { "FILTER_RESET", "FILTER_TYPE", "FILTER_FILES" };
Filter = "";
FilterType = "Contains";
numControls = _numControls;
MoveRightCommand = new DelegateCommand(MoveRight, CanMoveRight);
MoveLeftCommand = new DelegateCommand(MoveLeft, CanMoveLeft);
RemoveLastCharFromFilterCommand = new DelegateCommand(RemoveLastCharFromFilter, CanRemoveLastCharFromFilter);
ResetFiltersCommand = new DelegateCommand(ResetFilters, CanResetFilters);
EventMap = new Dictionary<string, Action>()
{
{"FILTER_MOVE_LEFT", () =>
{
if (MoveLeftCommand.CanExecute())
{
MoveLeftCommand.Execute();
}
}
},
{"FILTER_MOVE_RIGHT", () =>
{
if (MoveRightCommand.CanExecute())
{
MoveRightCommand.Execute();
}
}
},
{"CHAR_BACK", () =>
{
if (RemoveLastCharFromFilterCommand.CanExecute())
{
RemoveLastCharFromFilterCommand.Execute();
}
}
}
};
EventMapParam = new Dictionary<string, Action<string>>()
{
{"CHAR_SELECT", AppendToFilter},
{"VOS_OPTION", (_filterType) =>
{
FilterType = _filterType;
}
}
};
filterViewToken = this.iEventAggregator.GetEvent<PubSubEvent<ViewEventArgs>>().Subscribe(
(viewEventArgs) =>
{
EventHandler(viewEventArgs);
}
);
}
示例4: Generic_DelegateCommand_Receives_Execute_Parameter
public void Generic_DelegateCommand_Receives_Execute_Parameter()
{
int executeParameter = 0;
var command = new DelegateCommand<int>(x => executeParameter = x);
command.Execute(55);
Assert.That(executeParameter, Is.EqualTo(55));
}
示例5: Calling_Execute_Runs_Delegate
public void Calling_Execute_Runs_Delegate()
{
bool commandWasRun = false;
var command = new DelegateCommand(() => commandWasRun = true);
command.Execute(null);
Assert.That(commandWasRun);
}
示例6: ConstructorWithOnlyExecuteMethodForExecuteTest
public void ConstructorWithOnlyExecuteMethodForExecuteTest()
{
var command = new DelegateCommand(m_CommandManager,
ExecuteMethod);
command.Execute();
Assert.True(m_IsExecuted,
"IsExecuted");
}
示例7: TestNullObjectParameterCommand
public void TestNullObjectParameterCommand()
{
DelegateCommand<object, object> testMessageOutputCommand = new
DelegateCommand<object, object>(WriteTestMessage, null, null);
using (var writer = new StringWriter())
{
Console.SetOut(writer);
testMessageOutputCommand.Execute();
Assert.AreEqual("is that working??!!"+ Environment.NewLine, writer.ToString());
}
}
示例8: TestTwoParameterCommand
public void TestTwoParameterCommand()
{
TestReceiver receiver1 = new TestReceiver();
ICommand testMessageOutputCommand = new
DelegateCommand<string, string>(receiver1.ReceiverAction, "hello", "yunyun");
using (var writer = new StringWriter())
{
Console.SetOut(writer);
testMessageOutputCommand.Execute();
Assert.AreEqual("hellois that working yunyun" + Environment.NewLine, writer.ToString());
}
}
示例9: DelegateCommand
public VM主窗口()
{
AddProgress = new DelegateCommand((o) => _AddProgress());
ScanFiles = new DelegateCommand((o) => _ScanFiles(o));
WinClose = new DelegateCommand((o) => _WinClose());
OpenFile = new DelegateCommand((o) => _OpenFile(o));
LocateFile = new DelegateCommand((o) => _LocateFile());
Edit = new DelegateCommand((o) => _Edit(o));
CopyName = new DelegateCommand((o) => _CopyName());
Search = new DelegateCommand((o) => _Search());
ShowDetails = new DelegateCommand((o) => _ShowDetails());
VisitBgm = new DelegateCommand((o) => _VisitBgm());
VisitHP = new DelegateCommand((o) => _VisitHP());
Manage = new DelegateCommand((o) => _Manage());
Update = new DelegateCommand((o) => _Update());
Finish = new DelegateCommand((o) => _Finish());
UpdateInfo = new DelegateCommand((o) => _UpdateInfo());
MusicInfo = new DelegateCommand((o) => _MusicInfo());
ScanFiles.Execute(null);
}
示例10: AddEditPasswordViewModel
public AddEditPasswordViewModel(INavigationService navigationService, IPasswordRepository passwordRepository)
{
_navigationService = navigationService;
_passwordRepository = passwordRepository;
SaveCommand = new DelegateCommand(() => Save(), () => CanSave);
CopyToClipboardCommand = new DelegateCommand(() => CopyToClipboard());
GoBackCommand = new DelegateCommand(() => navigationService.GoBack(), () => navigationService.CanGoBack());
KeyPressAction = (eventArgs) =>
{
switch (eventArgs.Key)
{
case VirtualKey.Enter:
{
if(CanSave)
SaveCommand.Execute();
}
break;
default:
break;
}
};
}
示例11: Execute_PassesArgument_GenericStruct
public void Execute_PassesArgument_GenericStruct()
{
MockCommandHandler<int> handler = new MockCommandHandler<int>();
DelegateCommand<int> command = new DelegateCommand<int>(handler.Execute);
command.Execute(42);
CollectionAssert.AreEqual(new[] { 42 }, (ICollection)handler.ArgumentList);
}
示例12: Execute_PassesArgument_GenericClass
public void Execute_PassesArgument_GenericClass()
{
MockCommandHandler<MockArgumentClass> handler = new MockCommandHandler<MockArgumentClass>();
DelegateCommand<MockArgumentClass> command = new DelegateCommand<MockArgumentClass>(handler.Execute);
MockArgumentClass argument = new MockArgumentClass();
command.Execute(argument);
CollectionAssert.AreEqual(new[] { argument }, (ICollection)handler.ArgumentList);
}
示例13: Execute_CallsExecuteMethod_GenericStruct
public void Execute_CallsExecuteMethod_GenericStruct()
{
MockCommandHandler<int> handler = new MockCommandHandler<int>();
DelegateCommand<int> command = new DelegateCommand<int>(handler.Execute);
Assert.AreEqual(0, handler.ExecuteCallCount);
command.Execute(42);
Assert.AreEqual(1, handler.ExecuteCallCount);
}
示例14: Execute_CallsExecuteMethod_GenericClass
public void Execute_CallsExecuteMethod_GenericClass()
{
MockCommandHandler<MockArgumentClass> handler = new MockCommandHandler<MockArgumentClass>();
DelegateCommand<MockArgumentClass> command = new DelegateCommand<MockArgumentClass>(handler.Execute);
Assert.AreEqual(0, handler.ExecuteCallCount);
command.Execute(new MockArgumentClass());
Assert.AreEqual(1, handler.ExecuteCallCount);
}
示例15: Execute_CallsExecuteMethod_NonGeneric
public void Execute_CallsExecuteMethod_NonGeneric()
{
MockCommandHandler handler = new MockCommandHandler();
DelegateCommand command = new DelegateCommand(handler.Execute);
Assert.Equal(0, handler.ExecuteCallCount);
command.Execute(new MockArgumentClass());
Assert.Equal(1, handler.ExecuteCallCount);
}