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
See notes in RelayCommand(Action<T?>).
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
AsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
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
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecute
orcanExecute
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
AsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecute
orcanExecute
are null.
AsyncRelayCommand(Func<T?, Task>)
Initializes a new instance of the AsyncRelayCommand<T> class.
public AsyncRelayCommand(Func<T?, Task> execute)
Parameters
Remarks
See notes in RelayCommand(Action<T?>).
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
AsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
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
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
execute
orcanExecute
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
AsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
execute
orcanExecute
are null.
Properties
CanBeCanceled
public bool CanBeCanceled { get; }
Property Value
ExecutionTask
public Task? ExecutionTask { get; }
Property Value
IsCancellationRequested
public bool IsCancellationRequested { get; }
Property Value
IsRunning
public bool IsRunning { get; }
Property Value
Methods
CanExecute(object?)
public bool CanExecute(object? parameter)
Parameters
parameter
object
Returns
CanExecute(T?)
public bool CanExecute(T? parameter)
Parameters
parameter
T
Returns
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
ExecuteAsync(T?)
public Task ExecuteAsync(T? parameter)
Parameters
parameter
T
Returns
NotifyCanExecuteChanged()
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
public event EventHandler? CanExecuteChanged
Event Type
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged