I want to highlight selected text in a wpf textbox while the textbox is not focused. In my application, my textbox never gets focus, and every key input is done manually.
You can use the following code to achieve your purpose:
textBoxToHighlight.Focus();
textBoxToHighlight.Select(0, textBoxToHighlight.Text.Length);
Hope this helps.
Another alternative:
textBoxName.SelectAll();
I really like this type of selection:
textbox.Focus();
textbox.SelectionStart = 0;
textbox.SelectionLength = textbox.Text.Lenght;