是否有可能点击一个按钮,而不会失去对TextBox的焦点? [英] Is it possible to click a Button without ever losing focus on a TextBox?

查看:147
本文介绍了是否有可能点击一个按钮,而不会失去对TextBox的焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#WPF项目中开发一个触摸屏键盘控件,当TextBox获得焦点时它将可见,而当TextBox失去焦点时隐藏。我见过的触摸屏键盘项目已经通过将键盘定义为一个新窗口而不是一个控件来实现这一点。



对于我的应用程序,我真的很想键盘作为主应用程序窗口内的控件。有没有办法让一个按钮被点击(在键盘控制上),而不会导致文本框失去焦点?理想情况下,我想只在克拉的当前位置放置一个字符。

设置 Focusable =False在按钮上。你仍然可以用鼠标点击它,它仍然会调用你的click事件处理程序,但是它不会获得焦点或者导致TextBox失去焦点。

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.

解决方案

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.

这篇关于是否有可能点击一个按钮,而不会失去对TextBox的焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆