Is it possible to detect Keyboard focus events globally?

后端 未结 4 2353
眼角桃花
眼角桃花 2021-02-19 12:52

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:47

    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
    );
    

提交回复
热议问题