CommandBinding.Executed 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
执行与此 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用于将 和 CanExecuteRoutedEventArgs 处理程序映射到 ExecutedRoutedEventHandlerOpen 命令。
<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 |
- 相应的隧道事件为 PreviewExecuted。