Juan Pablo Gomez
Juan Pablo Gomez

Reputation: 5534

SelectOnEntry for wpf textbox?

I want to select all text into a textbox just when it got focus , there is a property named SelectOnEntry in wpf texbox or an equivalent?

If Not how to implment it ?

Upvotes: 0

Views: 136

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81263

Attach handler for GotFocus event:

<TextBox GotFocus="TextBox_GotFocus"/>

and in handler:

private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
    ((TextBox)sender).SelectAll();
}

If you need to do it in pure XAML way, you can create an attached property to select all text on focus. Refer to the solution here.

Upvotes: 2

Related Questions