In This Article

DelegateCommand<T> Class

Provides an ICommand implementation based on delegates.

public class DelegateCommand<T>
Type Parameters:
T -

The parameter type.

Inheritance:
object object
Derived:
PreviewableDelegateCommand<T>

Constructors

DelegateCommand(Action<T?>, Func<T?, bool>?)

Initializes an instance of the class.

public DelegateCommand(Action<T?> executeAction, Func<T?, bool>? canExecuteFunc = null)
Parameter Type Description
executeAction Action<T>

The execute action.

canExecuteFunc Func<T, bool>

The can-execute function, or null if the command is always enabled.

Methods

CanExecute(T?)

Defines the method that determines whether the command can execute in its current state.

public bool CanExecute(T? parameter)
Parameter Type Description
parameter T

Data used by the command. If the command does not require data to be passed, this object can be set to null.

Returns

bool:

true if this command can be executed; otherwise, false.

Execute(T?)

Defines the method to be called when the command is invoked.

public void Execute(T? parameter)
Parameter Type Description
parameter T

Data used by the command. If the command does not require data to be passed, this object can be set to null.

RaiseCanExecuteChanged()

Raises the CanExecuteChanged event.

public void RaiseCanExecuteChanged()

Events

CanExecuteChanged

Occurs when changes occur that affect whether or not the command should execute.

public event EventHandler? CanExecuteChanged

Event Type

EventHandler

Inherited Members

Extension Methods