Get and restore WPF keyboard focus

前端 未结 2 1365
野趣味
野趣味 2020-12-09 21:01

In a WPF program I want to get the current (keyboard) Focus, store it and re-set it later.

To get the current focus right now I use:

DependencyObject         


        
2条回答
  •  半阙折子戏
    2020-12-09 21:13

    First, you should use Keyboard.ClearFocus() and write Keyboard.Focus("Your Input element") later.

    Keyboard.ClearFocus() clear your focus reference. After, you can do focus to whatever element of your interface.

提交回复
热议问题