Class RelayCommand<T>
A generic _command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute method is true. This class allows you to accept _command parameters in the Execute(T) and CanExecute(T) callback methods.
Inheritance
Namespace: ISynergy.Framework.Mvvm.Commands
Assembly: ISynergy.Framework.Mvvm.dll
Syntax
public sealed class RelayCommand<T> : object, IRelayCommand<T>, IRelayCommand
Type Parameters
Name | Description |
---|---|
T | The type of parameter being passed as input to the callbacks. |
Constructors
View SourceRelayCommand(Action<T>)
Initializes a new instance of the RelayCommand<T> class that can always _execute.
Declaration
public RelayCommand(Action<T> execute)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | execute | The execution logic. |
Remarks
Due to the fact that the T
is a reference type,
you should always declare it as nullable, and to always perform checks within execute
.
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 execution logic. |
Predicate<T> | canExecute | The execution status logic. |
Remarks
See notes in RelayCommand(Action<T>).
Methods
View SourceCanExecute(T)
Provides a strongly-typed variant of
Declaration
public bool CanExecute(T parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | The input parameter. |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the current command can be executed. |
Remarks
Use this overload to avoid boxing, if T
is a value type.
CanExecute(Nullable<Object>)
Declaration
public bool CanExecute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | parameter |
Returns
Type | Description |
---|---|
System.Boolean |
Execute(T)
Provides a strongly-typed variant of
Declaration
public void Execute(T parameter)
Parameters
Type | Name | Description |
---|---|---|
T | parameter | The input parameter. |
Remarks
Use this overload to avoid boxing, if T
is a value type.
Execute(Nullable<Object>)
Declaration
public void Execute(object? parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | parameter |
NotifyCanExecuteChanged()
Notifies that the
Declaration
public void NotifyCanExecuteChanged()
Events
View SourceCanExecuteChanged
Declaration
public event EventHandler? CanExecuteChanged
Event Type
Type | Description |
---|---|
System.Nullable<EventHandler> |