title: How do I select all the text in a WPF textbox on click
body: <p>I have several TextBoxes within a UniformGrid.</p>
  
  <p>I want to select all the within a textbox when it is clicked I'd rather the event came from the uniformgrid. I was able to implement selecting all the text with GotKeyboardFocus for when I use only the keyboard with the code below in the handler. However when I merely click on the box it highlights while my mouse is down and on mouse up the cursor appears rather than the text remaining selected.</p>
  
  <pre><code>    foreach(TextBox Box in grid.Children)
      {
          if (Box.IsKeyboardFocusWithin)
          {
              Box.SelectAll();
              e.Handled = true;
              break;
          }
      }
  </code></pre>
  
  <p>I also have an PreviewKeyUp handler that watches for a max number of letters then moves to the next box. Also each box is initialized with the max number of letters when the screen loads. Which is why I want to do a select all on the text in the textbox so it can be typed over easily.</p>
  
  <p>I was able to use GotMouseCapture almost perfectly except that it doesn't work if you click near the text only near the edge of the textbox.</p>