How to get the focused control in WPF?

后端 未结 2 1596
名媛妹妹
名媛妹妹 2021-01-13 07:03

How can I get a current focused control in WPF?

I found some solution for WinForms, but invoking WIN32 API function, didn\'t work in WPF?

Is there any way fo

2条回答
  •  隐瞒了意图╮
    2021-01-13 07:48

    Here's what I did

    protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
    {
        lostFocusControl = e.OldFocus;
    }
    
    private void PauseButton_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        // invoke OnPreviewLostKeyboardFocus handler
    }
    

提交回复
热议问题