Focus on a TextBox in a DataTemplate
问题 I have DataTemplate containing a TextBox . I'm setting this template to a listbox item on a selection. I'm unable to set focus to textbox in the template. I tried to call MyTemplate.FindName, but it ends up with an Invalid Operation Exception: This operation is valid only on elements that have this template applied. How can I access it? 回答1: Since you know the name of the TextBox you want to focus, this becomes relatively easy. The idea is to get hold of the template as it's applied to the