In my experience, when the caret gets out of sync with the text it tends to stay out of sync. It is configuring the caret in the Xaml
that seems to set it off on the wrong track. Waiting until the window has loaded before setting the TextBox
focus or positioning the caret in the code behind usually gives more consistent results.
private void OnGotFocus(object sender, RoutedEventArgs e)
{
var textBox = sender as TextBox;
if (textBox == null) return;
textBox.SelectionStart = textBox.Text.Length;
textBox.SelectionLength = 0;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
ForeNameTB.Focus();
}