Finding out which control has focus [duplicate]
Asked Answered
P

1

8

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

Pigg answered 10/11, 2011 at 9:39 Comment(1)
every control has a property HasFocus. You might use it in some way to figure your requirementsFlemming
G
23

Like this

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

Use FocusManager

Gallo answered 10/11, 2011 at 9:44 Comment(2)
The namespace is System.Windows.Input and is part of the PresentationCore.dll assembly.Berkley
as described here link FocusManager.GetFocusedElement() requires the focus-scope as parameter. I used FocusManager.GetFocusedElement(this)Hadji

© 2022 - 2024 — McMap. All rights reserved.