Skip to content

AsyncRelayCommand

Rico Suter edited this page Jun 6, 2015 · 3 revisions
  • Package: MyToolkit (PCL)
  • Platforms: All (PCL)
  • Inherits from CommandBase.

An ICommand implementation to create a command with a given task-based async method. The command cannot be executed again until the running task has been finished (the command's CanExecute property is false until the task has finished, then CanExecute is calculated using the given predicate).

public MyViewModel() // ctor
{
    DeletePersonCommand = new AsyncRelayCommand<Person>(
        DeletePersonAsync, person => person != null);
    
    ...
}

private async Task DeletePersonAsync(Person person)
{
    // TODO: Add your code
}

// or with an async lambda:

DeletePersonCommand = new AsyncRelayCommand<Person>(async person => 
{
    // TODO: Add your code
});
Clone this wiki locally