ICommand Interface

ICommand Interface

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Defines the contract for commanding.

Namespace:  System.Windows.Input
Assembly:  System (in System.dll)
XMLNS for XAML: Not mapped to an xmlns.

[TypeConverterAttribute("System.Windows.Input.CommandConverter, PresentationFramework, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public interface ICommand

XAML Values


A reference to an ICommand implementation that describes the command logic. Typically this is done through a {Binding} reference to a data source, when using view-view model designs.

The ICommand type exposes the following members.

Public methodCanExecuteDefines the method that determines whether the command can execute in its current state.
Public methodExecuteDefines the method to be called when the command is invoked.

Public eventCanExecuteChangedOccurs when changes occur that affect whether the command should execute.

The ICommand interface enables the abstraction of a parameterized method call through its Execute method. In addition, you determine whether a method can be called prior to calling it with the CanExecute method.

Typically objects implement this interface to enable method calls on the objects through the use of XAML bindings. This is particularly useful in Model-View-ViewModel (MVVM) scenarios, as it allows models to expose commands to which controls such as buttons can be bound to without requiring additional code.

Windows Phone implements a limited commanding surface area, rather than an entire commanding. The classes that support command-initiated user interaction are the following:

You can bind the Command property of these objects and their derived classes to instances of objects that implement ICommand. In addition, the ICommand interface exists for compatibility, which is helpful if control authors migrate WPF code-defined or particularly markup-defined command bindings for a Windows Phone implementation.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft