How can I get a current focused control in WPF?
如何在WPF中获得当前的焦点控制?
I found some solution for WinForms, but invoking WIN32 API function, didn't work in WPF?
我找到了WinForms的一些解决方案,但调用WIN32 API函数,在WPF中不起作用?
Is there any way for doing it in WPF?
在WPF中有没有办法做到这一点?
2 个解决方案
#1
7
I know this is a late answer, but maybe people searching can find this helpful, I it found on msdn in the "Navigating Focus Programmatically" section close to the bottom of the page:
我知道这是一个迟到的答案,但也许搜索的人可以发现这很有帮助,我在msdn的页面底部的“以编程方式导航”部分中找到了它:
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
#2
5
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
}
#1
7
I know this is a late answer, but maybe people searching can find this helpful, I it found on msdn in the "Navigating Focus Programmatically" section close to the bottom of the page:
我知道这是一个迟到的答案,但也许搜索的人可以发现这很有帮助,我在msdn的页面底部的“以编程方式导航”部分中找到了它:
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
#2
5
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
}