Despite some posts on this forum and others I cannot find something that tells me how to set the focus on a TextBox.
I have a UserControl with many Labels and TextBoxes. When the Form is loaded, I want a particular TextBox to have the focus.
I have set the TabIndex but that didn’t seem to work.
Any suggestions?
You can use the
FocusManager.FocusedElementattached property for this purpose. Here’s a piece of code that set the focus to TxtB by default.You can also use
TxtB.Focus()in your code-behind if you don’t want to do this in XAML.