Is it possible to detect Keyboard focus events globally?
wpf
Solution
You can hook to the tunneling preview events:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="350" Width="525"
PreviewGotKeyboardFocus="Window_PreviewGotKeyboardFocus"
PreviewLostKeyboardFocus="Window_PreviewLostKeyboardFocus">
....
This way, as shown above, the window would be notified before all descendants when any of the descendants gets or loses the keyboard focus.
Read this for more information.
Problem
The following events can be used, but, they must be attach for each element: GotKeyboardFocus, LostKeyboardFocus Is there a way in .NET WPF to globally detect if the focused element changed ? without having to add event listeners for all possible elements ?