ExecutedRoutedEventArgs.Command 属性

定义

获取调用过的命令。Gets the command that was invoked.

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

属性值

ICommand

与此事件关联的命令。The command associated with this event.

示例

下面的示例创建一个 ExecutedRoutedEventHandler 用于处理多个命令的。The following example creates an ExecutedRoutedEventHandler that handles multiple commands. 处理程序将检查 Command 上的属性 ExecutedRoutedEventArgs ,以确定要调用的方法。The handler checks the Command property on the ExecutedRoutedEventArgs to determine which method to call.

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

注解

与事件关联的命令可以强制转换为的特定实现 ICommand ,如 RoutedCommand ,如果该类型已知,则为。The command associated with the event can be cast to the specific implementation of ICommand, such as a RoutedCommand, if the type is known.

适用于

另请参阅