Class RelayCommand<T>
Implementation of IRelayCommand that allows for CommandParameter to be passed in.
Inherited Members
Namespace: Unity.AppUI.MVVM
Assembly: Unity.AppUI.MVVM.dll
Syntax
public class RelayCommand<T> : IRelayCommand<T>, IRelayCommand, ICommand
Type Parameters
Name | Description |
---|---|
T | The type of the CommandParameter. |
Constructors
RelayCommand(Action<T?>)
Initializes a new instance of the RelayCommand<T> class.
Declaration
public RelayCommand(Action<T?> execute)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | execute | The action to execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the action is null. |
RelayCommand(Action<T?>, Predicate<T?>)
Initializes a new instance of the RelayCommand<T> class.
Declaration
public RelayCommand(Action<T?> execute, Predicate<T?> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | execute | The action to execute. |
Predicate<T> | canExecute | The predicate executed to determine if the command can execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the action or the predicate is null. |
Methods
CanExecute(object?)
Determines whether this RelayCommand<T> can execute in its current state.
Declaration
public bool CanExecute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | Data used by the command. |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the |
CanExecute(T?)
Determines whether this RelayCommand<T> can execute in its current state.
Declaration
public bool CanExecute(T? parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | Data used by the command. |
Returns
Type | Description |
---|---|
bool |
Execute(object?)
Executes the RelayCommand<T> on the current command target.
Declaration
public void Execute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | Data used by the command. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the |
Execute(T?)
Executes the RelayCommand<T> on the current command target.
Declaration
public void Execute(T? parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | Data used by the command. |
NotifyCanExecuteChanged()
Notifies that the CanExecuteChanged property has changed.
Declaration
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
Event raised when CanExecute(object?) changes.
Declaration
public event EventHandler? CanExecuteChanged
Event Type
Type | Description |
---|---|
EventHandler |