yu yang Jian
yu yang Jian

Reputation: 7165

How to detect current focused textbox?

I've tried -this- but it seems not work in WPF,

and saw -here- it says it'll be complicated.

So how to detect the current focused textbox in C# WPF?

Upvotes: 0

Views: 1558

Answers (1)

Hexie
Hexie

Reputation: 4213

There seem to be a few ways of doing this, depending on what it is exactly that you are wanting.

  • Loop through all the controls (of type TextBox) and check the focused property (ensure controls are set to focusable).
  • Use the FocusManager.GetFocusedElement method
  • Consider using this SO answer, snippet - UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

Upvotes: 2

Related Questions