Table of Contents

Class RelayCommand

Namespace
EasySoftware.MvvmMini
Assembly
EasySoftware.MvvmMini.dll

An asynchronous command without a parameter.

public class RelayCommand : RelayCommandBase, IRelayCommand, ICommand
Inheritance
RelayCommand
Implements
Inherited Members

Constructors

RelayCommand(Func<Task>)

Initializes a command that can always execute.

public RelayCommand(Func<Task> execute)

Parameters

execute Func<Task>

The work to run when the command executes.

Exceptions

ArgumentNullException

execute is null.

RelayCommand(Func<Task>, Func<bool>)

Initializes a command whose availability is re-evaluated through CommandManager.

public RelayCommand(Func<Task> execute, Func<bool> canExecute)

Parameters

execute Func<Task>

The work to run when the command executes.

canExecute Func<bool>

Returns whether the command can execute.

Exceptions

ArgumentNullException

execute is null.

RelayCommand(Func<Task>, Func<bool>, bool)

Initializes a command.

public RelayCommand(Func<Task> execute, Func<bool> canExecute, bool useCommandManager)

Parameters

execute Func<Task>

The work to run when the command executes.

canExecute Func<bool>

Returns whether the command can execute, or null if it always can.

useCommandManager bool

true to re-evaluate CanExecute(object) through CommandManager; false to re-evaluate it only when RaiseCanExecuteChanged() is called.

Exceptions

ArgumentNullException

execute is null.

Methods

CanExecute(object)

Determines whether the command can execute in its current state.

public override bool CanExecute(object parameter)

Parameters

parameter object

The command parameter.

Returns

bool

true if the command can execute; otherwise false.

Execute(object)

Executes the command without waiting for it to finish. Use ExecuteAsync(object) to await it.

public override void Execute(object parameter)

Parameters

parameter object

The command parameter.

ExecuteAsync(object)

Executes the command and returns a task that completes when the work is done.

public override Task ExecuteAsync(object parameter)

Parameters

parameter object

The command parameter.

Returns

Task

A task that represents the execution.