Is it possible to detect Keyboard focus events globally?

后端 未结 4 1702
无人及你
无人及你 2021-02-19 12:45

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

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 13:29

    You can add a routed event handler to your main window and specify you're interested in handled events.

    mainWindow.AddHandler(
        UIElement.GotKeyboardFocusEvent,
        OnElementGotKeyboardFocus,
        true
    );
    

提交回复
热议问题