Class AsyncRelayCommand<T>
A generic command that provides a more specific version of AsyncRelayCommand.
Inherited Members
Namespace: Unity.AppUI.MVVM
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 |
---|---|
Boolean |
Implements
executionTask
Gets a value indicating whether this AsyncRelayCommand<T> is currently running.
Declaration
public Task executionTask { get; set; }
Property Value
Type | Description |
---|---|
Task |
Implements
isCancellationRequested
Gets a value indicating whether this AsyncRelayCommand<T> has been cancelled.
Declaration
public bool isCancellationRequested { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
isRunning
Gets a value indicating whether this AsyncRelayCommand<T> is currently running.
Declaration
public bool isRunning { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
Methods
Cancel()
Cancels the current execution of this AsyncRelayCommand<T>.
Declaration
public void Cancel()
Implements
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 |
---|---|
Boolean | True if this command can be executed; otherwise, false. |
Implements
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 |
---|---|
Boolean | True if this command can be executed; otherwise, false. |
Implements
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. |
Implements
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. |
Implements
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. |
Implements
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. |
Implements
Exceptions
Type | Condition |
---|---|
InvalidOperationException | ExecuteAsync(T) has not been called. |
NotifyCanExecuteChanged()
Raises CanExecuteChanged.
Declaration
public void NotifyCanExecuteChanged()
Implements
Events
CanExecuteChanged
Event raised when the CanExecute(Object) property changes.
Declaration
public event EventHandler CanExecuteChanged
Event Type
Type | Description |
---|---|
EventHandler |
Implements
PropertyChanged
Event raised when the executionTask property changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |