title: How to select all text in TextBox WPF when focused?
body: <p>I have tried the below code to select all text in textbox when focus. But this is not working. </p>
  
  <p><strong>XAML</strong>:</p>
  
  <pre><code>        &lt;TextBox Text="test1" Width="100" Height="200"  
             GotFocus="TextBox_GotFocus"&gt;&lt;/TextBox&gt;
  </code></pre>
  
  <p><strong>c#:</strong></p>
  
  <pre><code>private void TextBox_GotFocus(object sender, RoutedEventArgs e)
          {
              (sender as TextBox).SelectAll();    
              //(sender as TextBox).Select(0, (sender as TextBox).Text.Length);
              (sender as TextBox).Focus();  
              e.Handled = true;
          } 
  </code></pre>
  
  <p>I have tried with asynchronous also. Surf lots , but nothing works.
  Please suggest?</p>