【发布时间】:2015-05-08 12:23:29
【问题描述】:
这是我的代码:
var commandBinding = new CommandBinding(ApplicationCommand.New);
commandBinding.PreviewExecuted += OnPreviewExecuted;
commandBinding.Executed += OnExecuted;
CommandBindings.Add(commandBinding);
void OnPreviewExecuted(object sender, ExecutedRoutedEventArgs e) {
e.Handled = false;
}
void OnExecuted(object sender, ExecutedRoutedEventArgs e) {
DoSomething();
}
MSDN 说:“...如果未处理预览事件,则在命令目标上引发 Executed 事件。”
这确实适用于 PreviewCanExecute 事件。但在这种情况下,当 PreviewExecuted-Event 正在侦听时,不会调用 Executed-Event。
我没有找到有关此主题的任何内容,所以我想问一下,这种行为是有意的还是不正确的。
【问题讨论】:
-
可能是其他地方的代码得到了事件(通过隧道)并处理了它。
-
基本没有。即使在只有一个按钮和上面代码的全新简约示例项目中也会发生这种行为。
标签: c# wpf routed-commands