WPF TextBox select all on Tab focus
<p>I'm trying to select all the text when the <strong>focus is done with the Tab key</strong>. But I'm not able to find the right solution. Now I'm using the <strong>GotFocusEvent</strong> but now when i click with the mouse it raises the event. </p>

<p>The code that I'm using now is:</p>

<pre><code>EventManager.RegisterClassHandler(typeof(System.Windows.Controls.TextBox), System.Windows.Controls.TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText));


void SelectAllText(object sender, RoutedEventArgs e)
{
    var textBox = sender as System.Windows.Controls.TextBox;
    if (textBox != null)
        if (!textBox.IsReadOnly)
            textBox.SelectAll();
}
</code></pre>