When I open the window MyWindow, I want to have the cursor of my keyboard pointing to the textbox contained in a user control that is contained in the window.
Usually, you would set FocusManager.FocusedElement={Binding ElementName=TextBoxToPutFocusOn}
.
But here, my constraint is that the textbox is inside a user control that is inside my window.
How can my window set focus to this textbox?
To illustrate, here are my 2 files:
MyWindow.xaml
<Window
xmlns:wpf="clr-namespace:MyWPFNamespace">
<StackPanel>
<TextBlock>Sample text</TextBlock>
<wpf:SpecialTextBox/>
</StackPanel>
</Window>
SpecialTextBox.xaml
<UserControl
x:Class="MyWPFNamespace.SpecialTextBox"
x:Name="SpecialName">
<TextBox
x:Name="TextBoxToPutFocusOn" />
</UserControl>
Thank you