Is it possible to click a Button without ever losing focus on a TextBox?

自古美人都是妖i 提交于 2019-12-23 08:04:20

问题


I am trying to develop a touchscreen keyboard control in a C# WPF project that will be visible when a TextBox gets focus and is hidden when the TextBox loses focus. The projects I have seen for touchscreen keyboards have accomplished this by defining the keyboard as a new window rather than a control.

For my application, I would really like to have the keyboard as a control within the main application window. Is there a way to allow a button to be clicked (on the keyboard control) without causing the TextBox to lose focus? Ideally, I would like to just place a character at the current position of the carat.


回答1:


Set Focusable="False" on the Button. You will still be able to click it with the mouse, and it will still call your click event handler, but it won't acquire focus or cause the TextBox to lose focus.




回答2:


An alternative is to use a PictureBox instead o a Button, then you would customize it. PictureBoxes don't lose focus when clicked.



来源:https://stackoverflow.com/questions/2010826/is-it-possible-to-click-a-button-without-ever-losing-focus-on-a-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!