Command Command Class

Definition

Defines an ICommand implementation that wraps a Action.

public class Command : System.Windows.Input.ICommand
type Command = class
    interface ICommand
Inheritance
CommandCommand
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) Command(Action)

Initializes a new instance of the Command class.

Command(Action<Object>) Command(Action<Object>)

Initializes a new instance of the Command class.

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

Initializes a new instance of the Command class.

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

Initializes a new instance of the Command class.

Methods

CanExecute(Object) CanExecute(Object)

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

ChangeCanExecute() ChangeCanExecute()

Send a CanExecuteChanged

Execute(Object) Execute(Object)

Invokes the execute Action

Events

CanExecuteChanged CanExecuteChanged

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

Extension Methods

LoadFromXaml<TXaml>(TXaml, String) LoadFromXaml<TXaml>(TXaml, String)

Returns an initialized view by loading the specified xaml.

LoadFromXaml<TXaml>(TXaml, Type) LoadFromXaml<TXaml>(TXaml, Type)

Returns a TXaml with the properties that are defined in the application manifest for callingType.

Applies to