打开停靠在 WPF 中的 Windows 10 触摸键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34769169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Windows 10 touch keyboard docked in WPF
提问by Bruno V
We started creating a WPF touch application in Windows 8 and recently migrated to Windows 10. One feature we implemented is opening the Windows Keyboard when a TextBoxreceives focus. In Windows 8, it was possible to dock the keyboard to the bottom by setting the registry setting EdgeTargetDockedStateand starting the TabTip process:
我们开始在 Windows 8 中创建 WPF 触摸应用程序,最近迁移到 Windows 10。我们实现的一项功能是在TextBox接收焦点时打开 Windows 键盘。在 Windows 8 中,可以通过设置注册表设置EdgeTargetDockedState并启动 TabTip 进程来将键盘停靠在底部:
string path = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
var info = new ProcessStartInfo(path);
info.WindowStyle = ProcessWindowStyle.Maximized;
var p = new Process();
p.StartInfo = info;
p.Start();
The Windows 10 keyboard however doesn't seem to have the same dock behavior as in Windows 8. The keyboard now overlays any maximized window which hides the bottom part of any application. Only not-maximized windows are resized to fit the remaining space.
然而,Windows 10 键盘似乎没有与 Windows 8 中相同的停靠行为。键盘现在覆盖任何隐藏任何应用程序底部的最大化窗口。只有未最大化的窗口才会调整大小以适应剩余空间。
I've checked the following links, but found no solution:
我检查了以下链接,但没有找到解决方案:
- https://superuser.com/questions/951841/windows-10-touch-keyboard-doesnt-dock-or-maximize-at-the-bottom-of-the-screen
- http://answers.microsoft.com/en-us/windows/forum/windows_10-desktop/windows-10-touch-keyboard-doesnt-dock/3c253400-568f-4e89-a253-0d7a747b5b63
- https://superuser.com/questions/951841/windows-10-touch-keyboard-doesnt-dock-or-maximize-at-the-bottom-of-the-screen
- http://answers.microsoft.com/en-us/windows/forum/windows_10-desktop/windows-10-touch-keyboard-doesnt-dock/3c253400-568f-4e89-a253-0d7a747b5b63
Can the Windows 10 keyboard be docked programmatically for a maximized window?
Windows 10 键盘可以以编程方式停靠以获得最大化的窗口吗?
回答by Макс Федотов
I open-sourced my project to automate everything concerning TabTip integration in WPF app.
我开源了我的项目,以自动化 WPF 应用程序中与 TabTip 集成相关的所有内容。
You can get it on nuget, and after that all you need is a simple config in your apps startup logic:
您可以在nuget上获取它,之后您只需要在应用程序启动逻辑中进行一个简单的配置:
TabTipAutomation.BindTo<TextBox>();
You can bind TabTip automation logic to any UIElement. Virtual Keyboard will open when any such element will get focus, and it will close when element will lose focus. Not only that, but TabTipAutomation will move UIElement (or Window) into view, so that TabTip will not block focused element.
您可以将 TabTip 自动化逻辑绑定到任何 UIElement。当任何此类元素获得焦点时,虚拟键盘将打开,当元素失去焦点时它将关闭。不仅如此,TabTipAutomation 还会将 UIElement(或 Window)移动到视图中,以便 TabTip 不会阻塞焦点元素。
For more info refer to the project site.
有关更多信息,请参阅项目站点。
To clarify: If you will be using this package TabTip will not be docked, but your UI will be in view, which i guess is what you wanted to achieve.
澄清:如果您将使用此包,TabTip 将不会停靠,但您的 UI 将在视图中,我想这就是您想要实现的。
回答by swdev95
Check this article: http://www.codeproject.com/Tips/1120263/Virtual-Keyboard-TabTip-integration-in-WPF-on-Win
检查这篇文章:http: //www.codeproject.com/Tips/1120263/Virtual-Keyboard-TabTip-integration-in-WPF-on-Win
Virtual Keyboard will open when any such element will get focus, and it will close when element will lose focus.
当任何此类元素获得焦点时,虚拟键盘将打开,当元素失去焦点时它将关闭。
回答by Shahin Dohan
EDIT:In the case when WindowStyle is set to None, please check out my answerhere. Also for manually handling touch keyboard appearance events, check out the sample code here.
编辑:在 WindowStyle 设置为 None 的情况下,请在此处查看我的答案。此外,对于手动处理触摸键盘外观事件,请在此处查看示例代码。
The answers here are quite old, currently the touch keyboard works just fine when tapping any textbox, even if the window is maximized.
这里的答案很旧,目前触摸键盘在点击任何文本框时都能正常工作,即使窗口最大化。
I recommend targeting at least .NET 4.6.2to get the best support for touch keyboards in Windows 10, due to a bug in WPF that was fixed in that version. Read more here, scroll down to WPF section.
我建议至少.NET 4.6.2在 Windows 10 中获得对触摸键盘的最佳支持,因为该版本中修复了 WPF 中的错误。在这里阅读更多,向下滚动到 WPF 部分。
The only thing you'll have to do is design your XAML in a way that your user interface can react properly when the touch keyboard shows up. Usually putting your content inside a ScrollViewerlike so should be enough:
您唯一需要做的就是设计您的 XAML,使您的用户界面能够在触摸键盘出现时做出正确反应。通常将您的内容放在一个ScrollViewerlike so 中就足够了:
<ScrollViewer PanningMode="VerticalOnly"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Disabled"
<!--Content here-->
</ScrollViewer>
But for more advanced scenarios, like moving buttons that are at the bottom to above the keyboard, you'll need to write your XAML inside the ScrollViewermore carefully, for example by using grids with dynamic heights.
但是对于更高级的场景,例如将键盘底部的按钮移动到键盘上方,您需要ScrollViewer更仔细地在内部编写 XAML ,例如使用具有动态高度的网格。
Hope this helps!
希望这可以帮助!

