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
executeActionThe execution logic.
Exceptions
- ArgumentNullException
Thrown if
executeis 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
executeorcanExecuteare null.
Methods
CanExecute(object?)
public bool CanExecute(object? parameter)
Parameters
parameterobject
Returns
Execute(object?)
public void Execute(object? parameter)
Parameters
parameterobject
NotifyCanExecuteChanged()
public void NotifyCanExecuteChanged()
Events
CanExecuteChanged
public event EventHandler? CanExecuteChanged