使用Tab键完成焦点时,我正在尝试选择所有文本。但是我找不到正确的解决方案。现在,我正在使用GotFocusEvent,但是现在当我用鼠标单击时,它将引发该事件。
我现在使用的代码是:
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();
}
Run Code Online (Sandbox Code Playgroud)