Skip to content

RelayCommand

Artem Kirgizov edited this page May 31, 2021 · 5 revisions

The RelayCommand class implements the ICommand interface and allows to set the behavior of the Execute method using a delegate. In addition, a generalized version of the class is implemented.

The main features of the class:

IList<string> list = new List<string>();

ICommand command = new RelayCommand(arg =>
{
    list.Add((string)arg);
});

command.Execute("string");
IList<string> list = new List<string>();

ICommand command = new RelayCommand<string>(arg =>
{
    list.Add(arg);
});

command.Execute("string");