Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commands

David Sungaila edited this page Sep 20, 2020 · 2 revisions

Define a class, derive from PresentationBase.ViewModelCommand<> and pass your ViewModel as the generic type. Make sure there is a parameterless constructor (or none at all).

Override CanExecute to define when the command can or cannot be executed.

Implement Execute for the code your command should … execute.

public class AlertCommand : ViewModelCommand<AwesomeViewModel>
{
    public override void Execute(AwesomeViewModel parameter)
    {
        System.Windows.MessageBox.Show("You just clicked that button.");
    }

    public override bool CanExecute(AwesomeViewModel parameter)
    {
        return parameter.Name != "John Doe";
    }
}