I'm trying to understand how WPF implements the routed commands which, internally, are themselves implemented by routed events. In the UIElement
class definition, we find this piece of code:
EventManager.RegisterClassHandler(type, CommandDevice.CommandDeviceEvent, new
CommandDeviceEventHandler(UIElement.OnCommandDeviceThunk), false);
From there on, the UIElement.OnCommandDeviceThunk
handler will pass along all the information through arguments of functions it calls in its body which themselves do the same until it reaches the CommandBinding.Executed
event which we subscribe to, thus executing our response code.
What I can't seem to find, and would like to understand, is who raises the CommandDevice.CommandDeviceEvent
?
When, for example, I have linked a ButtonBase
subclass object's Command
property to an ApplicationCommands command, does it raise the CommandDeviceEvent
in some way and how does it do it?
I understand the GlobalEventManager
holds scores of lists of event handlers, but I haven't yet understood who raises the events to trigger those handlers?