我想在用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();
}