I have a TextBox I use to display a file path and I'd like the caret and focus to always be at the end of path rather than the front. I've accomplished this with the help of this question: Setting cursor at end of textbox. It works!
InitializeComponent();
FilePathTextBox.Focus();
FilePathTextBox.Select(FilePathTextBox.Text.Length, 0);
However, I added a browse button to the user could select their own save location, and when the folder select dialog closes, the caret returns to the front of the file path again. I tried using the click event on the browse button to call the above code but it does not work.
private void BrowseBtnClick(object sender, RoutedEventArgs e)
{
BackupFileLocationTextBox.Focus();
BackupFileLocationTextBox.Select(BackupFileLocationTextBox.Text.Length, 0);
BackupFileLocationTextBox.CaretIndex = BackupFileLocationTextBox.Text.Length;
}
Any idea how to do this?