Show / Hide Table of Contents

Class AsyncDelegateCommand<T>

Implements IAsyncDelegateCommand<T>

Inheritance
System.Object
AsyncDelegateCommandBase
AsyncDelegateCommand<T>
Implements
IAsyncDelegateCommand<T>
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<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 Source

AsyncDelegateCommand(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.

View Source

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 Source

CanExecute(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

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

View Source

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 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<T>
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