Class RelayCommand<T>
- Namespace
- EasySoftware.MvvmMini
- Assembly
- EasySoftware.MvvmMini.dll
An asynchronous command that takes a parameter of type T.
public class RelayCommand<T> : RelayCommandBase, IRelayCommand, ICommand
Type Parameters
TThe type of the command parameter.
- Inheritance
-
RelayCommand<T>
- Implements
- Inherited Members
Constructors
RelayCommand(Func<T, Task>)
Initializes a command that can always execute.
public RelayCommand(Func<T, Task> execute)
Parameters
Exceptions
- ArgumentNullException
executeis null.
RelayCommand(Func<T, Task>, Func<T, bool>)
Initializes a command whose availability is re-evaluated through CommandManager.
public RelayCommand(Func<T, Task> execute, Func<T, bool> canExecute)
Parameters
executeFunc<T, Task>The work to run when the command executes.
canExecuteFunc<T, bool>Returns whether the command can execute for a given parameter.
Exceptions
- ArgumentNullException
executeis null.
RelayCommand(Func<T, Task>, Func<T, bool>, bool)
Initializes a command.
public RelayCommand(Func<T, Task> execute, Func<T, bool> canExecute, bool useCommandManager)
Parameters
executeFunc<T, Task>The work to run when the command executes.
canExecuteFunc<T, bool>Returns whether the command can execute for a given parameter, or null if it always can.
useCommandManagerbooltrue to re-evaluate CanExecute(object) through CommandManager; false to re-evaluate it only when RaiseCanExecuteChanged() is called.
Exceptions
- ArgumentNullException
executeis null.
Methods
CanExecute(object)
Determines whether the command can execute in its current state.
public override bool CanExecute(object parameter)
Parameters
parameterobjectThe command parameter.
Returns
Execute(object)
Executes the command without waiting for it to finish. Use ExecuteAsync(object) to await it.
public override void Execute(object parameter)
Parameters
parameterobjectThe command parameter.
ExecuteAsync(object)
Executes the command and returns a task that completes when the work is done.
public override Task ExecuteAsync(object parameter)
Parameters
parameterobjectThe command parameter.
Returns
- Task
A task that represents the execution.