共用方式為


ExecutedRoutedEventArgs.Command 屬性

定義

取得已叫用的命令。

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

屬性值

與這個事件相關聯的命令。

範例

下列範例會 ExecutedRoutedEventHandler 建立可處理多個指令的 。 處理程式會 Command 檢查 上的 ExecutedRoutedEventArgs 屬性,以判斷要呼叫的方法。

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

適用於

另請參閱