How can I set an event handler (such as keydown
) to entire solution, not a single window?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Well,
KeyDown
will work only in the current window, because you need focus forKeyDown
. What you can do is add a handler to all windows and dispatch another event in those handlers, then register all classes that you need with this new event.alternatively, have a look at the
Observer
patternHow about this:
You should use a delegate, to connect the event(wherever it is) and the function your willing to work when the event jumps.
you can load as many events as you want to your delegate.
mzE.
Register a global event handler in your application class (App.cs), like this:
This will handle the
KeyDown
event for anyWindow
in your app. You can caste
toKeyEventArgs
to get to the information about the pressed key.You can't.
Eighter you register the event in all windows and pass it on to a global function/event or (in case of the keydown or similar) you use some global "event catching" (like THIS for the keyboard).