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
TThe 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
cancelableExecuteFunc<T, CancellationToken, Task>The cancelable execution logic.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecuteis 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
cancelableExecuteFunc<T, CancellationToken, Task>The cancelable execution logic.
optionsAsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecuteis 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
cancelableExecuteFunc<T, CancellationToken, Task>The cancelable execution logic.
canExecutePredicate<T>The execution status logic.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecuteorcanExecuteare 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
cancelableExecuteFunc<T, CancellationToken, Task>The cancelable execution logic.
canExecutePredicate<T>The execution status logic.
optionsAsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
cancelableExecuteorcanExecuteare 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
executeis null.
AsyncRelayCommand(Func<T?, Task>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand<T> class.
public AsyncRelayCommand(Func<T?, Task> execute, AsyncRelayCommandOptions options)
Parameters
executeFunc<T, Task>The execution logic.
optionsAsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
executeis 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
executeorcanExecuteare 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
executeFunc<T, Task>The execution logic.
canExecutePredicate<T>The execution status logic.
optionsAsyncRelayCommandOptionsThe options to use to configure the async command.
Remarks
See notes in RelayCommand(Action<T?>).
Exceptions
- ArgumentNullException
Thrown if
executeorcanExecuteare 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
parameterobject
Returns
CanExecute(T?)
public bool CanExecute(T? parameter)
Parameters
parameterT
Returns
Cancel()
public void Cancel()
Execute(object?)
public void Execute(object? parameter)
Parameters
parameterobject
Execute(T?)
public void Execute(T? parameter)
Parameters
parameterT
ExecuteAsync(object?)
public Task ExecuteAsync(object? parameter)
Parameters
parameterobject
Returns
ExecuteAsync(T?)
public Task ExecuteAsync(T? parameter)
Parameters
parameterT
Returns
NotifyCanExecuteChanged()
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
public event EventHandler? CanExecuteChanged
Event Type
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged