Selecting entire text when text box gets focus

Selecting entire text when text box gets focus

Post by a2F5c2llaG » Fri, 01 Jun 2007 04:49:00


I am trying to find out how to format my text box on a form in a way that
when the textbox gets focus it selects all the text in that box.
 
 
 

Selecting entire text when text box gets focus

Post by Corrado Ca » Fri, 01 Jun 2007 06:34:57

No idea of how to do it using exclusively Blend (Any hint appreciated) you
can however have it done using RoutedEvent
Adding: TextBox.GotFocus="OnGotFocus" on <Window> Tag and adding

private void OnGotFocus (object sender, RoutedEventArgs e)
{
(e.OriginalSource as TextBox).SelectAll();
}

on Codebehind will do the trick.

HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.yqcomputer.com/
Weblog: http://www.yqcomputer.com/