Partilhar via


ExecutedRoutedEventArgs.Command Propriedade

Definição

Obtém o comando que foi invocado.

public:
 property System::Windows::Input::ICommand ^ Command { System::Windows::Input::ICommand ^ get(); };
public System.Windows.Input.ICommand Command { get; }
member this.Command : System.Windows.Input.ICommand
Public ReadOnly Property Command As ICommand

Valor da propriedade

O comando associado a esse evento.

Exemplos

O exemplo a seguir cria um ExecutedRoutedEventHandler que manipula vários comandos. O manipulador verifica a Command propriedade no ExecutedRoutedEventArgs para determinar qual método chamar.

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();
        }
    }
}
Private Sub ExecutedDisplayCommand(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim command As RoutedCommand = TryCast(e.Command, RoutedCommand)

    If command IsNot Nothing Then
        If command Is MediaCommands.Pause Then
               MyPauseMethod()
        End If
        If command Is MediaCommands.Play Then
               MyPlayMethod()
        End If
        If command Is MediaCommands.Stop Then
               MyStopMethod()
        End If
    End If
End Sub

Comentários

O comando associado ao evento pode ser convertido para a implementação específica de ICommand, como um RoutedCommand, se o tipo for conhecido.

Aplica-se a

Confira também