This documentation is archived and is not being maintained.

MenuItem.Command Property

Gets or sets the Command property.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public ICommand Command { get; set; }
/** @property */
public final ICommand get_Command ()

/** @property */
public void set_Command (ICommand value)

public final function get Command () : ICommand

public function set Command (value : ICommand)

For XAML information, see the ICommand type.

Property Value

The default value is null.

Identifier Field


Metadata Flags


This property is used to associate a command with a particular MenuItem instance. The following example associates the Copy command with a MenuItem and automatically supplies the input gesture text Ctrl+C but it does not bind to the application command. For information on how to bind to the desired command see Add a Command to a MenuItem.

<MenuItem Command="ApplicationCommands.Copy"/>

A command is raised when a MenuItem is clicked; just after the Click event. The command is raised on the element using the following priorities:

  1. If CommandTarget is set on the MenuItem that element is used.

  2. The PlacementTarget of a ContextMenu that contains the MenuItem.

  3. The focus target of the main window that contains a Menu.

  4. The MenuItem that was clicked.

The following examples show how to use the command property to associate commands with menu items.

<MenuItem Command="ApplicationCommands.Open">
<MenuItem Command="ApplicationCommands.Close">

mib = new MenuItem();
mib.Command = System.Windows.Input.ApplicationCommands.Copy;
mib.Header = "_Copy";

mic = new MenuItem();
mic.Command = System.Windows.Input.ApplicationCommands.Paste;
mic.Header = "_Paste";

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0