CanExecuteRoutedEventArgs.Command Property

Definition

Gets the command associated with this event.

C#
public System.Windows.Input.ICommand Command { get; }

Property Value

The command. Unless the command is a custom command, this is generally a RoutedCommand. There is no default value.

Examples

The following example creates a CanExecuteRoutedEventHandler which handles multiple commands. If the Command property is equal to the Play command and the method IsPlaying returns false, CanExecute is set to true; otherwise, CanExecute is set to false. If the Command property is equal to the Stop command and the method IsPlaying returns true, CanExecute is set to true; otherwise, CanExecute is set to false.

C#
private void CanExecuteDisplayCommand(object sender,
    CanExecuteRoutedEventArgs e)
{
    RoutedCommand command = e.Command as RoutedCommand;

    if (command != null)
    {
        if (command == MediaCommands.Play)
        {
            if (!IsPlaying())
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }

        if (command == MediaCommands.Stop)
        {
            if (IsPlaying())
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }
    }
}

Remarks

For more information on commanding, see the Commanding Overview.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also