Share via


Command Class

Definition

Defines an System.Windows.Input.ICommand implementation that wraps a System.Action.

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

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, Func<Boolean>)

Initializes a new instance of the Command class.

Command(Action)

Initializes a new instance of the Command class.

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

Initializes a new instance of the Command class.

Command(Action<Object>)

Initializes a new instance of the Command class.

Methods

CanExecute(Object)

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

ChangeCanExecute()

Send a System.Windows.Input.ICommand.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