3

When I execute a routed command, let's say:

ApplicationCommands.Undo.Execute(null, this);

WPF does some magic to find the proper CommandBinding on which it executes the ExecutedRoutedEventHandler.

Is there a way to get a reference to the CommandBinding (or at least to the handler) that would be executed?

It would sometimes be nice for debugging to know who is handling a command.

Stefan
  • 4,187
  • 1
  • 32
  • 38
  • Yes, I agree. I tried stepping into the .NET framework source for ApplicationCommands.Undo.Exececute(null, this); but I only got "No Source Available". Gonna try and clear my local symbol cache and try again. In the callstack I'm especially interested in PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(object sender = ... :-) – Fredrik Hedblad Oct 23 '10 at 15:51

1 Answers1

0

You can try to check the CommandBinding lists in:

       UIElement
       ContentElement 
       UIElement3D

ApplicationCommands are checking internally if sender has particular command in CommandBinding. In addition if sender is null then Keyboard.FocusedElement is assigned as sender.

klm_
  • 1,199
  • 1
  • 10
  • 26