Class AsyncDelegateCommand<T>
Implements IAsyncDelegateCommand<T>
Namespace: Sartorius.SAF.Presentation.Commands
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public sealed class AsyncDelegateCommand<T> : AsyncDelegateCommandBase, IAsyncDelegateCommand<T>, ICommand
Type Parameters
Name | Description |
---|---|
T | The type of the command parameter. |
Examples
The following example shows how to use the AsyncDelegateCommand<T>.
[Export]
public class UpdateViewModel
{
private readonly IItemService service;
private readonly AsyncDelegateCommand<Item> updateCommand;
[ImportingConstructor]
public UpdateViewModel(IItemService service)
{
this.service = service;
this.updateCommand = new AsyncDelegateCommand<Item>(OnUpdate, CanUpdate);
}
public ICommand UpdateCommand => this.updateCommand;
private Boolean CanUpdate(Item item)
{
return item.HasChanges;
}
private async Task OnUpdate(Item currentItem)
{
using (new BusyIndicator())
{
await this.service.AddAsync(new Item())
.ConfigureAwait(true);
} // disposal of BusyIndicator is done in UI thread
}
}
Constructors
View SourceAsyncDelegateCommand(Func<T, Task>)
Creates a new instance of the AsyncDelegateCommand<T> class.
Declaration
public AsyncDelegateCommand(Func<T, Task> executeFunc)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Threading.Tasks.Task> | executeFunc | The Function executed when System.Windows.Input.ICommand.Execute(System.Object) or ExecuteAsync(T) is called. |
AsyncDelegateCommand(Func<T, Task>, Func<T, Boolean>)
Creates a new instance of the AsyncDelegateCommand<T> class.
Declaration
public AsyncDelegateCommand(Func<T, Task> executeFunc, Func<T, bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.Threading.Tasks.Task> | executeFunc | The Function executed when System.Windows.Input.ICommand.Execute(System.Object) or ExecuteAsync(T) is called. |
System.Func<T, System.Boolean> | canExecute | The Function that verifies whether or not AsyncCommand should execute. |
Methods
View SourceCanExecute(T)
Determines whether the command can execute in its current state
Declaration
public bool CanExecute(T parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | Data used by the command. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ExecuteAsync(T)
Defines the method to be called when the command is invoked.
Declaration
public async Task ExecuteAsync(T parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | Data used by the command. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | The task object representing the asynchronous operation. |
Explicit Interface Implementations
View SourceICommand.CanExecute(Object)
Declaration
bool ICommand.CanExecute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter |
Returns
Type | Description |
---|---|
System.Boolean |
ICommand.Execute(Object)
Declaration
void ICommand.Execute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parameter |