ExecutedRoutedEventArgs.Command 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會拿到被召喚的指令。
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若已知型別,則可投射到。