Cursor Focus on Textbox in WPF/C#(光标聚焦在 WPF/C# 中的文本框上)
问题描述
我目前正在创建屏幕键盘.我正在使用 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# 中的文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:光标聚焦在 WPF/C# 中的文本框上


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01