Class RelayCommand
A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute(object?) method is true. This type does not allow you to accept command parameters in the Execute(object?) and CanExecute(object?) callback methods.
Inherited Members
Namespace: Unity.AppUI.MVVM
Assembly: Unity.AppUI.MVVM.dll
Syntax
public class RelayCommand : IRelayCommand, ICommand
Constructors
RelayCommand(Action?)
Initializes a new instance of the RelayCommand<T> class.
Declaration
public RelayCommand(Action? execute)
Parameters
Type | Name | Description |
---|---|---|
Action | execute | The action to execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the action is null. |
RelayCommand(Action, Func<bool>)
Initializes a new instance of the RelayCommand<T> class.
Declaration
public RelayCommand(Action execute, Func<bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Action | execute | The action to execute. |
Func<bool> | canExecute | Predicate used to determine if the command can execute. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the action is null. |
Methods
CanExecute()
Initializes a new instance of the RelayCommand class.
Declaration
public bool CanExecute()
Returns
Type | Description |
---|---|
bool |
CanExecute(object?)
Determines whether this RelayCommand 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 |
Execute()
Defines the method to be called when the command is invoked.
Declaration
public void Execute()
Execute(object?)
Executes the RelayCommand on the current command target.
Declaration
public void Execute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
object | parameter | Data used by the command. |
NotifyCanExecuteChanged()
Notifies that the CanExecuteChanged property has changed.
Declaration
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
Occurs when changes occur that affect whether or not the command should execute.
Declaration
public event EventHandler? CanExecuteChanged
Event Type
Type | Description |
---|---|
EventHandler |