ExecutedRoutedEventArgs.Command Property

Definition

Gets the command that was invoked.

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

Property Value

The command associated with this event.

Examples

The following example creates an ExecutedRoutedEventHandler that handles multiple commands. The handler checks the Command property on the ExecutedRoutedEventArgs to determine which method to call.

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

    if(command != null)
    {
        if(command == MediaCommands.Pause)
        {
               MyPauseMethod();
        }
        if(command == MediaCommands.Play)
        {
               MyPlayMethod();
        }
        if(command == MediaCommands.Stop)
        {
               MyStopMethod();
        }
    }
}

Remarks

The command associated with the event can be cast to the specific implementation of ICommand, such as a RoutedCommand, if the type is known.

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