Cris
Cris

Reputation: 12194

How to set the focus on a user control item in WPF?

I have a WPF app that uses different instances of a User Control; when the user clicks a button on the main window I need to set the focus on the textbox inside the currently active instance of the user control.

Which is the best way to set the focus on that child item?

Upvotes: 1

Views: 835

Answers (1)

Konrad Morawski
Konrad Morawski

Reputation: 8394

child.Focus();

or

VisualTreeHelper.GetChild(parent, 0).Focus(); // you might want to test it for nulls

Upvotes: 1

Related Questions