How to get focused control in WPF?

How can I get the current focused control in WPF?

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

Is there a way to do this in WPF?

+4
source share
3 answers

Here is what i did

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

I know this is a late answer, but maybe finding people can find this useful, I found it on msdn in the "Navigation" Focus Programmatically "section at the bottom of the page:

 UIElement elementWithFocus = Keyboard.FocusedElement as UIElement; 
+7
source

Try entering the code for this blog . Pass the root visual form element for Helpers.FindFocusedElement .

+1
source

Source: https://habr.com/ru/post/1343836/


All Articles