简体   繁体   English

在WPF中替换Windows 7+屏幕键盘

[英]Replacing Windows 7+ onscreen keyboard in WPF

I maintain/develop a C&C application typically used on touchscreens . 我维护/开发通常在触摸屏上使用的C&C应用程序。 Most text boxes require numeric input, so most of the normal keyboard is pointless. 大多数文本框都需要数字输入,因此大多数普通键盘是毫无意义的。 My boss wants me to build a number pad without a keyboard for these boxes. 我的老板要我为这些盒子建立一个不带键盘数字键盘 (We do have other, alphanumeric boxes, too.) The user can select a checkbox to indicate whether the onscreen keyboard is needed. (我们也有其他字母数字框。)用户可以选择一个复选框,以指示是否需要屏幕键盘。

I learned from How to disable the little touch-keyboard on Windows edit controls how to ensure that the standard Windows keyboard doesn't appear for my application. 我从“ 如何在Windows编辑器上禁用小触摸键盘”中学到了如何确保标准Windows键盘不会出现在我的应用程序中。 The registry 's ugly, but at least it allows me to play nice with everyone. 注册表很丑陋,但至少它可以让我和所有人玩得很好。

Since the application is already built, I decided to look into using a resource dictionary to modify my text boxes in place; 由于已经构建了该应用程序,因此我决定考虑使用资源字典来修改我的文本框。 see Is it possible to set code behind a resource dictionary in WPF for event handling? 请参见是否可以在WPF中的资源字典后面设置代码以进行事件处理? . By the comments this is apparently also ugly, per WPF's design. 通过评论,按照WPF的设计,这显然也很丑陋。

Now I need to tell my code behind where the window (or other control) for the keyboard is. 现在,我需要在键盘窗口(或其他控件)的后面告诉代码。 That sounds like a XAML attribute - a dependency property . 这听起来像XAML属性- 依赖项属性 Unfortunately, ResourceDictionary doesn't extend DependencyObject , so it seems this technique is unworkable. 不幸的是, ResourceDictionary并没有扩展DependencyObject ,所以看来这种技术是行不通的。

Per WPF: Specific input textboxes (for phone numbers and such) , something like this would work if tapping would summon a keyboard with only allowed characters. WPF:特定输入文本框(电话号码和这样的) ,像这样将如果攻会召唤,只有允许的字符键盘工作。 Actually, that would be absolutely perfect . 实际上,那绝对是完美的 If only this were part of WPF and therefore integrated with the keyboard. 如果仅是WPF的一部分,并因此与键盘集成在一起。

But maybe part of my approach is wrong? 但是,也许我的方法的一部分是错误的? How can I get a number pad which appears when "number boxes" are selected? 当选择“数字框”时如何显示数字键盘? I really don't want to duplicate (as opposed to reference) a resource dictionary on every XAML page that involves a text box. 我真的不想在每个涉及文本框的XAML页面上复制(而不是引用)资源字典。

PS How is the question formatting? PS问题格式如何?

I think you're doing it backwards. 我认为您正在倒退。 I also had to write my own keyboard control (with various improvements that aren't relevant here), and the way I did it was by write a new textbox control that allows me to describe the kind of keyboard I want -- numerical or standard (again, and various other properties). 我还必须编写自己的键盘控件(此处没有进行各种改进),而我做到的方式是编写一个新的文本框控件,该控件可让我描述所需的键盘类型(数字或标准) (再次,以及其他各种属性)。

Now the control itself knows where it was touched (yeah, I know), and it can contain the necessary resources to both draw itself and the popup keyboard page. 现在,控件本身知道它被触摸的位置(是的,我知道),并且它可以包含必要的资源来绘制自身和弹出键盘页面。 You don't have to worry about anything but actually using it on your pages. 您不必担心什么,只需要在页面上实际使用即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM