Based on this link: Set the focus on a textbox in xaml wpf , Focus
can be set by setting FocusManager
at the StackPanel
and specifying the elementName. I did tried out and it works. I'm wondering what if I have only one textbox in my XAML
and StackPanel
is unnecessary?
Is there any other simple way to set focus given the scenario I only have one textbox?
I've also tried the second answer in the above link but doesn't work:
<TextBox Text="{Binding MyText}"
FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"/>