CommandBinding.Executed 事件

定义

在与此命令关联的 CommandBinding 命令执行时发生。

public:
 event System::Windows::Input::ExecutedRoutedEventHandler ^ Executed;
public event System.Windows.Input.ExecutedRoutedEventHandler Executed;
member this.Executed : System.Windows.Input.ExecutedRoutedEventHandler 
Public Custom Event Executed As ExecutedRoutedEventHandler 
Public Event Executed As ExecutedRoutedEventHandler 

事件类型

示例

以下示例创建一个 CommandBinding 将命令 ExecutedRoutedEventHandler 和处理程序 CanExecuteRoutedEventArgs 映射到该 Open 命令。

<Window.CommandBindings>
  <CommandBinding Command="ApplicationCommands.Open"
                  Executed="OpenCmdExecuted"
                  CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>
// Creating CommandBinding and attaching an Executed and CanExecute handler
CommandBinding OpenCmdBinding = new CommandBinding(
    ApplicationCommands.Open,
    OpenCmdExecuted,
    OpenCmdCanExecute);

this.CommandBindings.Add(OpenCmdBinding);
' Creating CommandBinding and attaching an Executed and CanExecute handler
Dim OpenCmdBinding As New CommandBinding(ApplicationCommands.Open, AddressOf OpenCmdExecuted, AddressOf OpenCmdCanExecute)

Me.CommandBindings.Add(OpenCmdBinding)

下面显示了 ExecutedRoutedEventHandler 执行命令时创建的 MessageBox 命令。

void OpenCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
    String command, targetobj;
    command = ((RoutedCommand)e.Command).Name;
    targetobj = ((FrameworkElement)target).Name;
    MessageBox.Show("The " + command +  " command has been invoked on target object " + targetobj);
}
Private Sub OpenCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim command, targetobj As String
    command = CType(e.Command, RoutedCommand).Name
    targetobj = CType(sender, FrameworkElement).Name
    MessageBox.Show("The " + command + " command has been invoked on target object " + targetobj)
End Sub

注解

RoutedCommand执行时,它会在命令目标上引发PreviewExecuted事件。 PreviewExecuted如果未处理该事件,则会Executed在命令目标上引发该事件。 如果命令目标具有CommandBinding特定命令,则调用该Executed命令的CommandBinding处理程序。 如果命令目标没有 CommandBinding 该特定命令,则 Executed 事件会弹出元素树,搜索与 CommandBinding 该命令关联的元素。 如果未找到命令 CommandBinding ,则不会处理该命令。

路由事件信息

项目 价值
标识符字段 ExecutedEvent
路由策略 鼓 泡
代理 ExecutedRoutedEventHandler

适用于

另请参阅