Table of Contents

Class AsyncRelayCommand<T>

Namespace
CommunityToolkit.Mvvm.Input
Assembly
CommunityToolkit.Mvvm.dll

A generic command that provides a more specific version of AsyncRelayCommand.

public sealed class AsyncRelayCommand<T> : IAsyncRelayCommand<T>, IAsyncRelayCommand, INotifyPropertyChanged, IRelayCommand<T>, IRelayCommand, ICommand

Type Parameters

T

The type of parameter being passed as input to the callbacks.

Inheritance
AsyncRelayCommand<T>
Implements
Inherited Members
Extension Methods

Constructors

AsyncRelayCommand(Func<T?, CancellationToken, Task>)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancelableExecute)

Parameters

cancelableExecute Func<T, CancellationToken, Task>

The cancelable execution logic.

Remarks

Exceptions

ArgumentNullException

Thrown if cancelableExecute is null.

AsyncRelayCommand(Func<T?, CancellationToken, Task>, AsyncRelayCommandOptions)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancelableExecute, AsyncRelayCommandOptions options)

Parameters

cancelableExecute Func<T, CancellationToken, Task>

The cancelable execution logic.

options AsyncRelayCommandOptions

The options to use to configure the async command.

Remarks

Exceptions

ArgumentNullException

Thrown if cancelableExecute is null.

AsyncRelayCommand(Func<T?, CancellationToken, Task>, Predicate<T?>)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancelableExecute, Predicate<T?> canExecute)

Parameters

cancelableExecute Func<T, CancellationToken, Task>

The cancelable execution logic.

canExecute Predicate<T>

The execution status logic.

Remarks

Exceptions

ArgumentNullException

Thrown if cancelableExecute or canExecute are null.

AsyncRelayCommand(Func<T?, CancellationToken, Task>, Predicate<T?>, AsyncRelayCommandOptions)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancelableExecute, Predicate<T?> canExecute, AsyncRelayCommandOptions options)

Parameters

cancelableExecute Func<T, CancellationToken, Task>

The cancelable execution logic.

canExecute Predicate<T>

The execution status logic.

options AsyncRelayCommandOptions

The options to use to configure the async command.

Remarks

Exceptions

ArgumentNullException

Thrown if cancelableExecute or canExecute are null.

AsyncRelayCommand(Func<T?, Task>)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, Task> execute)

Parameters

execute Func<T, Task>

The execution logic.

Remarks

Exceptions

ArgumentNullException

Thrown if execute is null.

AsyncRelayCommand(Func<T?, Task>, AsyncRelayCommandOptions)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, Task> execute, AsyncRelayCommandOptions options)

Parameters

execute Func<T, Task>

The execution logic.

options AsyncRelayCommandOptions

The options to use to configure the async command.

Remarks

Exceptions

ArgumentNullException

Thrown if execute is null.

AsyncRelayCommand(Func<T?, Task>, Predicate<T?>)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, Task> execute, Predicate<T?> canExecute)

Parameters

execute Func<T, Task>

The execution logic.

canExecute Predicate<T>

The execution status logic.

Remarks

Exceptions

ArgumentNullException

Thrown if execute or canExecute are null.

AsyncRelayCommand(Func<T?, Task>, Predicate<T?>, AsyncRelayCommandOptions)

Initializes a new instance of the AsyncRelayCommand<T> class.

public AsyncRelayCommand(Func<T?, Task> execute, Predicate<T?> canExecute, AsyncRelayCommandOptions options)

Parameters

execute Func<T, Task>

The execution logic.

canExecute Predicate<T>

The execution status logic.

options AsyncRelayCommandOptions

The options to use to configure the async command.

Remarks

Exceptions

ArgumentNullException

Thrown if execute or canExecute are null.

Properties

CanBeCanceled

public bool CanBeCanceled { get; }

Property Value

bool

ExecutionTask

public Task? ExecutionTask { get; }

Property Value

Task

IsCancellationRequested

public bool IsCancellationRequested { get; }

Property Value

bool

IsRunning

public bool IsRunning { get; }

Property Value

bool

Methods

CanExecute(object?)

public bool CanExecute(object? parameter)

Parameters

parameter object

Returns

bool

CanExecute(T?)

public bool CanExecute(T? parameter)

Parameters

parameter T

Returns

bool

Cancel()

public void Cancel()

Execute(object?)

public void Execute(object? parameter)

Parameters

parameter object

Execute(T?)

public void Execute(T? parameter)

Parameters

parameter T

ExecuteAsync(object?)

public Task ExecuteAsync(object? parameter)

Parameters

parameter object

Returns

Task

ExecuteAsync(T?)

public Task ExecuteAsync(T? parameter)

Parameters

parameter T

Returns

Task

NotifyCanExecuteChanged()

public void NotifyCanExecuteChanged()

Events

CanExecuteChanged

public event EventHandler? CanExecuteChanged

Event Type

EventHandler

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler