0

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 ?

Juan Pablo Gomez
  • 5,203
  • 11
  • 55
  • 101
  • If you want to do it with a "behaviour" (by way of an attached property) instead of code-behind, then see this: http://stackoverflow.com/questions/7808974/initial-focus-and-select-all-behavior – Colin Smith Jan 18 '14 at 14:27
  • Does this answer your question? [How to automatically select all text on focus in WPF TextBox?](https://stackoverflow.com/questions/660554/how-to-automatically-select-all-text-on-focus-in-wpf-textbox) – Eliahu Aaron May 13 '20 at 10:38

1 Answers1

2

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.

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185