Reputation: 4783
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 for doing it in WPF?
Upvotes: 5
Views: 14936
Reputation: 99
Another solution:
bool FocusedElement = FocusManager.GetFocusedElement(this);
Found here: https://stackoverflow.com/a/8077580/14648642
Upvotes: 0
Reputation: 4783
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
}
Upvotes: 6