Show / Hide Table of Contents

Class AsyncDelegateCommand

The AsyncDelegateCommand allows use the System.Windows.Input.ICommand interface with asynchronous functionality. While the underlying asynchronous functionality is running System.Windows.Input.ICommand.CanExecute(System.Object) always returns false and System.Windows.Input.ICommand.CanExecuteChanged is automatically called when execution starts and ends.

potential exceptions occurring during execution are automatically dispatched into the UI thread.

Inheritance
System.Object
AsyncDelegateCommandBase
AsyncDelegateCommand
Implements
IAsyncDelegateCommand
System.Windows.Input.ICommand
AsyncDelegateCommandBase.IsExecuting
AsyncDelegateCommandBase.CanExecuteChanged
AsyncDelegateCommandBase.RaiseCanExecuteChanged()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Sartorius.SAF.Presentation.Commands
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public sealed class AsyncDelegateCommand : AsyncDelegateCommandBase, IAsyncDelegateCommand, ICommand
Examples

The following example shows how to use the AsyncDelegateCommand.

    [Export]
public class AddViewModel
{
    private readonly AsyncDelegateCommand addCommand;
    private readonly IItemService service;

    [ImportingConstructor]
    public AddViewModel(IItemService service)
    {
        this.service = service;
        this.addCommand = new AsyncDelegateCommand(OnAdd);
    }

    public ICommand AddCommand => this.addCommand;

    private async Task OnAdd()
    {
        using (new BusyIndicator())
        {
            await this.service.AddAsync(new Item())
                      .ConfigureAwait(true);
        } // disposal of BusyIndicator is done in UI thread
    }
}

Constructors

View Source

AsyncDelegateCommand(Func<Task>)

Creates a new instance of the AsyncDelegateCommand class with the specified async execution function.

Declaration
public AsyncDelegateCommand(Func<Task> executeFunc)
Parameters
Type Name Description
System.Func<System.Threading.Tasks.Task> executeFunc

The asynchronous function that this command should execute.

View Source

AsyncDelegateCommand(Func<Task>, Func<Boolean>)

Creates a new instance of the AsyncDelegateCommand class with the specified async execution function and can execute function.

Declaration
public AsyncDelegateCommand(Func<Task> executeFunc, Func<bool> canExecute)
Parameters
Type Name Description
System.Func<System.Threading.Tasks.Task> executeFunc

The asynchronous function that this command should execute.

System.Func<System.Boolean> canExecute

The function that verifies whether the command can execute in its current state.

Methods

View Source

CanExecute()

Defines the method that determines whether the command can execute in its current state.

Declaration
public bool CanExecute()
Returns
Type Description
System.Boolean

true, if this command can be executed; otherwise, false.

View Source

ExecuteAsync()

Defines the method to be called when the command is invoked.

Declaration
public async Task ExecuteAsync()
Returns
Type Description
System.Threading.Tasks.Task

The task object representing the asynchronous operation.

Explicit Interface Implementations

View Source

ICommand.CanExecute(Object)

Declaration
bool ICommand.CanExecute(object parameter)
Parameters
Type Name Description
System.Object parameter
Returns
Type Description
System.Boolean
View Source

ICommand.Execute(Object)

Declaration
void ICommand.Execute(object parameter)
Parameters
Type Name Description
System.Object parameter

Implements

IAsyncDelegateCommand
System.Windows.Input.ICommand

Extension Methods

CollectionExtensions.AddRange<T, TCollection>(TCollection, IEnumerable<T>)
SerializableObjectCloneExtension.Clone<T>(T)

See Also

IAsyncDelegateCommand
  • View Source
Back to top Generated by DocFX