标签: wpf-textbox

WPF TextBox在Tab焦点上全选

使用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)

.net c# wpf keyboard-events wpf-textbox

4
推荐指数
1
解决办法
4341
查看次数

标签 统计

.net ×1

c# ×1

keyboard-events ×1

wpf ×1

wpf-textbox ×1