Command Class

Definition

Defines an ICommand implementation that wraps a Action.

public class Command : System.Windows.Input.ICommand
type Command = class
    interface ICommand
Inheritance
Command
Derived
Implements

Remarks

The following example creates a new Command and set it to a button.

var command = new Command (() => Debug.WriteLine ("Command executed"));
var button = new Button {
  Text = "Hit me to execute the command",
  Command = command,
};

More useful scenarios takes a parameter

var command = new Command (o => Debug.WriteLine ("Command executed: {0}", o));
var button = new Button {
  Text = "Hit me to execute the command",
  Command = command,
  CommandParameter = "button0",
};

Constructors

Command(Action)

Initializes a new instance of the Command class.

Command(Action, Func<Boolean>)

Initializes a new instance of the Command class.

Command(Action<Object>)

Initializes a new instance of the Command class.

Command(Action<Object>, Func<Object,Boolean>)

Initializes a new instance of the Command class.

Methods

CanExecute(Object)

Returns a Boolean indicating if the Command can be exectued with the given parameter.

ChangeCanExecute()

Send a CanExecuteChanged

Execute(Object)

Invokes the execute Action

Events

CanExecuteChanged

Occurs when the target of the Command should reevaluate whether or not the Command can be executed.

Applies to