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# 中的文本框上
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
