如何在WPF中获得集中控制?

Iga*_*gal 5 wpf controls focus

如何在WPF中获得当前的焦点控制?

我找到了WinForms的一些解决方案,但调用WIN32 API函数,在WPF中不起作用?

在WPF中有没有办法做到这一点?

Jam*_*Esh 7

我知道这是一个迟到的答案,但也许搜索的人可以发现这很有帮助,我在msdn的"编程导航焦点"部分中找到了靠近页面底部的内容:

UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
Run Code Online (Sandbox Code Playgroud)


Iga*_*gal 5

这就是我做的

protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
    lostFocusControl = e.OldFocus;
}

private void PauseButton_PreviewKeyDown(object sender, KeyEventArgs e)
{
    // invoke OnPreviewLostKeyboardFocus handler
}
Run Code Online (Sandbox Code Playgroud)