How to Select all text in WPF Textbox

In many scenarios, when user navigate to textbox, they want to directly enter a text rather than remove the current text only start typing the new text. In short this is what I want to achieve

Initially I thought can use SelectAll() method to do that

 

However, it doesn’t achieve what I want. The textbox look like below.

In order to achieve the solution, need to add another line of code which is Focus().

Now the cursor will point to the textbox and the text has been selected. User can directly enter any text they want without erase the existing text.

Hope it helps.

Advertisements

3 Comments

Filed under Uncategorized

3 responses to “How to Select all text in WPF Textbox

  1. ro

    Is there a way to do this with xaml code only?

  2. Walter

    Hi there,Can you describe to me in what condition you want to Select the Text? I bet there is a way u acn do so.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s