简体   繁体   English

为什么在单击 tabcontrol 内的 WPF 文本框时,Windows 10 键盘会出现并立即消失?

[英]Why does windows 10 keyboard appear and immediately dissapear when clicking in WPF textbox inside tabcontrol?

We have a strange behaviour on with our WPF application in Windows 10 (update 1803 - Microsoft Surface Go).我们的 WPF 应用程序在 Windows 10(更新 1803 - Microsoft Surface Go)上有一个奇怪的行为。

Inside the application I have a Tabcontrol and it has its ItemsSource bound in codebehind to a list of objects(based on a usercontrol).在应用程序内部,我有一个 Tabcontrol,它的 ItemsSource 在代码隐藏中绑定到对象列表(基于用户控件)。

Whenever I press inside a textbox, the windows 10 keyboard appears and disappears immediately.每当我在文本框内按下时,Windows 10 键盘都会立即出现并消失。 If I click in the textbox again, the keyboard appears correctly.如果我再次单击文本框,键盘将正确显示。 When I press in another textbox, the same happens again (keyboard appears/dissapears and I have to press again in the same textbox).当我按下另一个文本框时,同样的情况再次发生(键盘出现/消失,我必须在同一个文本框中再次按下)。

In other parts of the application this is NOT happening.在应用程序的其他部分,这不会发生。

Strangely enough, when I just got the tablet, I would have sworn this problem did NOT happen.奇怪的是,当我刚拿到平板电脑时,我会发誓这个问题没有发生。 Since then, windows has updated.从那时起,Windows 已经更新。

I suspect this has to do with one of the windows updates because the same application works fine on other tablets with windows 10 of another brand (one of these other tablets I am sure they have a windows 10 LTSB version from 2016).我怀疑这与其中一个 Windows 更新有关,因为相同的应用程序可以在其他带有另一个品牌的 Windows 10 的平板电脑上正常运行(这些其他平板电脑中的一个我确信它们有 2016 年的 Windows 10 LTSB 版本)。

I have tried to remove as many updates as I can But cannot remove the 1803 cumulative update.我已尝试删除尽可能多的更新,但无法删除 1803 累积更新。

The .Net version I was using is .Net 4.0 and I have tried to update to 4.7.2 without success.我使用的 .Net 版本是 .Net 4.0,我尝试更新到 4.7.2 没有成功。 As advised in this thread : C# WPF Windows 10 (1803) TouchKeyboard unreliable Issue (Prism ClickOnce)正如此线程中所建议的: C# WPF Windows 10 (1803) TouchKeyboard unreliable Issue (Prism ClickOnce)

I see that another person complains they have similar issues only after a specific windows 10 update.我看到另一个人抱怨他们只有在特定的 Windows 10 更新后才会遇到类似的问题。 https://social.msdn.microsoft.com/Forums/en-US/b9efb4eb-e0a9-4bf0-9985-57a673c42f79/wpf-application-windows-10-touch-keyboard-flickering-issue?forum=wpf https://social.msdn.microsoft.com/Forums/en-US/b9efb4eb-e0a9-4bf0-9985-57a673c42f79/wpf-application-windows-10-touch-keyboard-flickering-issue?forum=wpf

I have tried to switch to tablet mode and to desktop mode.我尝试切换到平板电脑模式和桌面模式。 In both the same behaviour occurs.在两者中都会发生相同的行为。 So, now I have defaulted to desktop mode with a "control panel"-setting where the keyboard appears if no physical keyboard is attached.所以,现在我已经默认使用“控制面板”设置桌面模式,如果没有连接物理键盘,键盘就会出现。 在此处输入图片说明


The only workaround That I have found is the following:我发现的唯一解决方法如下:

  1. Put the tabcontrol inside a Grid and gridrow and Create a second GridRow (height=0) with a textbox inside (The new Textbox MUST be outside the tabcontrol).将 tabcontrol 放在 Grid 和 gridrow 内,并创建第二个 GridRow (height=0),里面有一个文本框(新文本框必须在 tabcontrol 之外)。 When one of the tabs is pressed, put the focus on the newly created textbox.当按下其中一个选项卡时,将焦点放在新创建的文本框上。

    Keyboard.Focus(focusbox);键盘。焦点(焦点框);

When I do this, the keyboard does not dissapear the first time I press a textbox inside the tabcontrol.当我这样做时,键盘不会在我第一次按下 tabcontrol 内的文本框时消失。

Inherit your TabControl and override the OnCreateAutomationPeer :继承您的 TabControl 并覆盖OnCreateAutomationPeer

protected override AutomationPeer OnCreateAutomationPeer()
{
    return new FrameworkElementAutomationPeer(this);
}

For some reason when I keep it to the default TabControlAutomationPeer , I have the same issue where the automatically opened touch keyboard (the TabTip.exe) closes immediately after pressing a textbox inside any of the tabs of the TabControl.出于某种原因,当我将其保留为默认TabControlAutomationPeer 时,我遇到了同样的问题,即在按下 TabControl 的任何选项卡内的文本框后,自动打开的触摸键盘(TabTip.exe)立即关闭。 If I change it to FrameworkElementAutomationPeer it works perfectly.如果我将其更改为FrameworkElementAutomationPeer,它将完美运行。

However, I'm not completely sure what the downside of this solution is.但是,我不完全确定此解决方案的缺点是什么。 Whether there are any negative side effects.是否有任何负面影响。

Another solution might be to set registry key HKEY_CURRENT_USER\\Software\\Microsoft\\TabletTip\\1.7\\DisableNewKeyboardExperience to 1 , but that changes the appearance of the virtual keyboard to an older version, and the keyboard stays on screen after pressing another control.另一种解决方案可能是将注册表项HKEY_CURRENT_USER\\Software\\Microsoft\\TabletTip\\1.7\\DisableNewKeyboardExperience1 ,但这会将虚拟键盘的外观更改为旧版本,并且在按下另一个控件后键盘会停留在屏幕上。

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

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