Class RelayCommand
- Namespace
- CommunityToolkit.Mvvm.Input
- Assembly
- CommunityToolkit.Mvvm.dll
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.
public sealed class RelayCommand : IRelayCommand, ICommand
- Inheritance
-
RelayCommand
- Implements
- Inherited Members
Constructors
RelayCommand(Action)
Initializes a new instance of the RelayCommand class that can always execute.
public RelayCommand(Action execute)
Parameters
execute
ActionThe execution logic.
Exceptions
- ArgumentNullException
Thrown if
execute
is null.
RelayCommand(Action, Func<bool>)
Initializes a new instance of the RelayCommand class.
public RelayCommand(Action execute, Func<bool> canExecute)
Parameters
Exceptions
- ArgumentNullException
Thrown if
execute
orcanExecute
are null.
Methods
CanExecute(object?)
public bool CanExecute(object? parameter)
Parameters
parameter
object
Returns
Execute(object?)
public void Execute(object? parameter)
Parameters
parameter
object
NotifyCanExecuteChanged()
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
public event EventHandler? CanExecuteChanged