Class AsyncRelayCommand<T>
A generic command that provides a more specific version of AsyncRelayCommand.
Implements
Inherited Members
Namespace: Unity.AppUI.MVVM
Assembly: Unity.AppUI.MVVM.dll
Syntax
public class AsyncRelayCommand<T> : IAsyncRelayCommand<T>, IAsyncRelayCommand, INotifyPropertyChanged, IRelayCommand<T>, IRelayCommand, ICommand
Type Parameters
Name | Description |
---|---|
T | The type of parameter being passed as input to the callbacks. |
Constructors
AsyncRelayCommand(Func<T?, CancellationToken, Task>)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancellableExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<T, CancellationToken, Task> | cancellableExecute | The Func<T1, T2, TResult> to invoke when the command is executed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, CancellationToken, Task>, Predicate<T?>)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancellableExecute, Predicate<T?> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<T, CancellationToken, Task> | cancellableExecute | The Func<T1, T2, TResult> to invoke when the command is executed. |
Predicate<T> | canExecute | The Predicate<T> to invoke to determine whether the command can execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, CancellationToken, Task>, Predicate<T?>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancellableExecute, Predicate<T?> canExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<T, CancellationToken, Task> | cancellableExecute | The Func<T1, T2, TResult> to invoke when the command is executed. |
Predicate<T> | canExecute | The Predicate<T> to invoke to determine whether the command can execute. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use when executing the command. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, CancellationToken, Task>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, CancellationToken, Task> cancellableExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<T, CancellationToken, Task> | cancellableExecute | The Func<T1, T2, TResult> to invoke when the command is executed. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use when executing the command. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, Task>)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, Task> execute)
Parameters
Type | Name | Description |
---|---|---|
Func<T, Task> | execute | The Func<T, TResult> to invoke when the command is executed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, Task>, Predicate<T?>)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, Task> execute, Predicate<T?> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<T, Task> | execute | The Func<T, TResult> to invoke when the command is executed. |
Predicate<T> | canExecute | The Predicate<T> to invoke to determine whether the command can execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, Task>, Predicate<T?>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, Task> execute, Predicate<T?> canExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<T, Task> | execute | The Func<T1, T2, TResult> to invoke when the command is executed. |
Predicate<T> | canExecute | The Predicate<T> to invoke to determine whether the command can execute. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use when executing the command. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsyncRelayCommand(Func<T?, Task>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand<T> class.
Declaration
public AsyncRelayCommand(Func<T?, Task> execute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<T, Task> | execute | The Func<T, TResult> to invoke when the command is executed. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use when executing the command. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
canBeCancelled
Gets a value indicating whether this AsyncRelayCommand<T> can be cancelled.
Declaration
public bool canBeCancelled { get; }
Property Value
Type | Description |
---|---|
bool |
executionTask
Gets a value indicating whether this AsyncRelayCommand<T> is currently running.
Declaration
public Task? executionTask { get; set; }
Property Value
Type | Description |
---|---|
Task |
isCancellationRequested
Gets a value indicating whether this AsyncRelayCommand<T> has been cancelled.
Declaration
public bool isCancellationRequested { get; }
Property Value
Type | Description |
---|---|
bool |
isRunning
Gets a value indicating whether this AsyncRelayCommand<T> is currently running.
Declaration
public bool isRunning { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
CanExecute(object?)
Determines whether this AsyncRelayCommand<T> can execute in its current state.
Declaration
public bool CanExecute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | The parameter to use when determining whether the command can execute. |
Returns
Type | Description |
---|---|
bool | True if this command can be executed; otherwise, false. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | ExecuteAsync(T?) has not been called. |
CanExecute(T?)
Determines whether this AsyncRelayCommand<T> can execute in its current state.
Declaration
public bool CanExecute(T? parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | The parameter to use when determining whether the command can execute. |
Returns
Type | Description |
---|---|
bool | True if this command can be executed; otherwise, false. |
Cancel()
Cancels the current execution of this AsyncRelayCommand<T>.
Declaration
public void Cancel()
Execute(object)
Determines whether this AsyncRelayCommand<T> can execute in its current state.
Declaration
public void Execute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | The parameter to use when determining whether the command can execute. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | ExecuteAsync(T?) has not been called. |
Execute(T?)
Executes the AsyncRelayCommand<T> synchronously on the current thread.
Declaration
public void Execute(T? parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | The parameter to use when executing the command. |
ExecuteAsync(object?)
Gets a value indicating whether this AsyncRelayCommand<T> can be executed.
Declaration
public Task ExecuteAsync(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | The parameter to use when determining whether the command can execute. |
Returns
Type | Description |
---|---|
Task | True if this command can be executed; otherwise, false. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | ExecuteAsync(T?) has not been called. |
ExecuteAsync(T?)
Occurs when changes occur that affect whether the command should execute.
Declaration
public Task ExecuteAsync(T? parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | The parameter to use when determining whether the command can execute. |
Returns
Type | Description |
---|---|
Task | True if this command can be executed; otherwise, false. |
NotifyCanExecuteChanged()
Raises CanExecuteChanged.
Declaration
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
Event raised when the CanExecute(object?) property changes.
Declaration
public event EventHandler? CanExecuteChanged
Event Type
Type | Description |
---|---|
EventHandler |
PropertyChanged
Event raised when the executionTask property changes.
Declaration
public event PropertyChangedEventHandler? PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |