how to highlight/select text in a wpf textbox without focus?

user1340852 picture user1340852 · Aug 23, 2012 · Viewed 24.8k times · Source

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.

I was wondering if there is a way to highlight the selected text when the textbox is not focused?

Any help would be appreciated!

Answer

pdvries picture pdvries · Oct 21, 2012

You can use the following code to achieve your purpose:

textBoxToHighlight.Focus();
textBoxToHighlight.Select(0, textBoxToHighlight.Text.Length);

Hope this helps.