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,如果类型已知。