public DelegateCommand MyCommand { get; private set; } public MyViewModel() { MyCommand = new DelegateCommand(ExecuteMyCommand); } private void ExecuteMyCommand() { // Do some action here }
public DelegateCommandMyCommand { get; private set; } public MyViewModel() { MyCommand = new DelegateCommand (ExecuteMyCommand); } private void ExecuteMyCommand(string parameter) { // Do some action with the parameter here }
public DelegateCommand MyCommand { get; private set; } public MyViewModel() { MyCommand = new DelegateCommand( async () => await ExecuteMyCommandAsync(), () => CanExecuteMyCommand()); } private async Task ExecuteMyCommandAsync() { // Do some asynchronous action here } private bool CanExecuteMyCommand() { // Return true if the command is enabled, false otherwise }In this example, the DelegateCommand is used to bind a button click event, but this time with an asynchronous method called ExecuteMyCommandAsync. The CanExecuteMyCommand method determines whether the command is enabled or not. The Prism library can be found on the NuGet package manager or downloaded from the Prism website.