问题描述
我目前正在创建屏幕键盘.我正在使用 routedcommands 处理按钮单击.问题是当我单击键盘面板中的按钮时,焦点会转移到按钮而不是文本框上.该要求规定光标应始终出现在文本框中,以指示将插入下一个字符的位置.有没有一种方法可以让我在单击按钮时将注意力集中在文本框上.
I am currently in the process of creating a Onscreen keyboard. I am handling the button click using routedcommands. The issue is that when i click on the button in keyboard panel the focus shifts to the button rather than on the Textbox. The requirement states that a cursor should always appear in the text box to indicate the position where the next character will be inserted. Is there a way i can keep focus on the textbox while button is clicked.
推荐答案
为输入控件设置逻辑焦点
To set logical focus to an input control
FocusManager.SetFocusedElement(this, textboxJack); // set logical focus
将键盘焦点设置到输入控件
To set keyboard focus to an input control
Keyboard.Focus(textboxJill); // set keyboard focus
了解逻辑焦点和键盘焦点的区别
To know the difference between logical and keyboard focus
输入概述 - 关注 MSDN
这篇关于光标聚焦在 WPF/C# 中的文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!