【问题标题】:Find destination of a RoutedEvent查找 RoutedEvent 的目的地
【发布时间】:2010-10-23 13:55:47
【问题描述】:

当我执行路由命令时,假设:

ApplicationCommands.Undo.Execute(null, this);

WPF 做了一些魔法来找到正确的CommandBinding,在它上面执行ExecutedRoutedEventHandler

有没有办法获得对将被执行的CommandBinding(或至少是处理程序)的引用?

有时候调试知道谁在处理命令会很好。

【问题讨论】:

  • 是的,我同意。我尝试进入 ApplicationCommands.Undo.Execute(null, this); 的 .NET 框架源代码。但我只得到“没有可用的来源”。将尝试清除我的本地符号缓存并重试。在调用堆栈中,我对 PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(object sender = ... :-) 特别感兴趣

标签: c# wpf routed-commands


【解决方案1】:

您可以尝试检查以下中的 CommandBinding 列表:

       UIElement
       ContentElement 
       UIElement3D

ApplicationCommands 正在内部检查发送方是否在 CommandBinding 中有特定命令。此外,如果 sender 为 null,则将 Keyboard.FocusedElement 分配为 sender。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    相关资源
    最近更新 更多