Commands & events

Commanding is supported by Catel. Catel supports Command classes, which is also known as RelayCommand or DelegateCommand in other frameworks. Defining a command on a view model is very easy, as you can see in the code below:

// TODO: Move code below to constructor
Edit = new Command(OnEditExecute, OnEditCanExecute);
// TODO: Move code above to constructor

/// <summary>
/// Gets the Edit command.
/// </summary>
public Command Edit { get; private set; }

/// <summary>
/// Method to check whether the Edit command can be executed.
/// </summary>
private bool OnEditCanExecute()
{
    return true;
}

/// <summary>
/// Method to invoke when the Edit command is executed.
/// </summary>
private void OnEditExecute()
{
    // TODO: Handle command logic here
}

There are some people who don’t like the ICommand implementations. For example, Caliburn (Micro) uses convention and does not require the creation of a command. There are a few downsides for that:


Contributions

We would like to thank the following contributors:

Want to contribute to the documentation? We have a guide for that!


Questions

Have a question about Catel? Use StackOverflow with the Catel tag!