8

Is there a way to figure out which control in my visualtree has focus? This is mostly for debugging.

Perry
  • 2,250
  • 2
  • 19
  • 24

1 Answers1

23

Like this

bool FocusedElement = FocusManager.GetFocusedElement() == textBox;

Use FocusManager

  • The namespace is System.Windows.Input and is part of the PresentationCore.dll assembly. – crunchy Jun 06 '14 at 15:55
  • as described here [link](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.focusmanager.getfocusedelement?view=windowsdesktop-7.0#system-windows-input-focusmanager-getfocusedelement(system-windows-dependencyobject)) `FocusManager.GetFocusedElement()` requires the focus-scope as parameter. I used `FocusManager.GetFocusedElement(this)` – Tom667 Aug 25 '23 at 06:40