Xamarin.Forms Guides | Samples

Xamarin.Forms.Command Class

Defines an ICommand implementation that wraps a Action.

See Also: Command

Syntax

public class Command : ICommand

Remarks

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

C# Example

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

C# Example

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",
};

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.Command are listed below.

See Also: Object

Public Constructors

Initializes a new instance of the Command class.
Initializes a new instance of the Command class.
Initializes a new instance of the Command class.
Initializes a new instance of the Command class.

Public Methods

CanExecute(Object) : Boolean
Returns a Boolean indicating if the Command can be exectued with the given parameter.
ChangeCanExecute()
Send a ICommand.CanExecuteChanged
Execute(Object)
Invokes the execute Action

Public Events

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