1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Cris
  • 12,124
  • 27
  • 92
  • 159
  • Duplicate of [WPF - Set Focus when a button is clicked - No Code Behind](http://stackoverflow.com/questions/2204063/wpf-set-focus-when-a-button-is-clicked-no-code-behind) – Jakub Aug 04 '11 at 13:52
  • This question does not specify that he doesn't want it in code behind. – Konrad Morawski Aug 04 '11 at 13:54

1 Answers1

1
child.Focus();

or

VisualTreeHelper.GetChild(parent, 0).Focus(); // you might want to test it for nulls
Konrad Morawski
  • 8,307
  • 7
  • 53
  • 91