Share via


Command Class

Definition

Defines an ICommand implementation that wraps a Action.

public ref class Command : System::Windows::Input::ICommand
public class Command : System.Windows.Input.ICommand
type Command = class
    interface ICommand
Public Class Command
Implements 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

Name Description
Command(Action, Func<Boolean>)

Creates a new command with the specified parameterless execute and canExecute delegates.

Command(Action)

Creates a new command with the specified parameterless execute action.

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

Creates a new command with the specified execute and canExecute delegates.

Command(Action<Object>)

Creates a new command with the specified execute action.

Methods

Name Description
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

Name Description
CanExecuteChanged

Applies to