即使我将焦点设置为控件,Windows 10 uwp 也会隐藏软键盘 [英] Windows 10 uwp hide soft keyboard even when I set focus to a control

查看:22
本文介绍了即使我将焦点设置为控件,Windows 10 uwp 也会隐藏软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 10 移动版 uwp 应用,但有两个问题.

I have a Windows 10 mobile uwp app and I am having two issues.

首先,我将焦点设置为应用中的控件.我通过成功使用公共调用来做到这一点

First, I set focus to controls in the app. I do this by using the common call successfully

 Control.Focus(FocusState.Programmatic);

但是,在某些情况下这不起作用.大多数情况下确实如此,但例如,当我的页面加载时,我试图在其中一个字段中设置初始焦点,但它不起作用.我在两个地方试过这个电话.首先,在页面的构造函数中,在 InitializeComponenets 之后以及覆盖 onNavigatedTo 方法中.在哪里调用它的最佳位置?它可能不起作用的原因是什么,尤其是在实例化新页面时?

However, there are some cases where this does not work. Most times it does but for example, when my page loads, I am trying to set an initial focus in one of the fields and it does not work. I have tried this call in two places. First, in the constructor for the page, after InitializeComponenets and also in the override onNavigatedTo method. Where is the best place to call this and what are some reasons why it may not appear to work, particularly when a new page is instantiated?

第二,与设置焦点有关.我的 UI 上有一个文本框,我使用上面列出的相同的程序化焦点调用来设置控件.但是,软(屏幕)键盘会在发生这种情况时显示.我不希望它在我以编程方式设置焦点时显示,但如果用户选择该字段,则显示它.场景是我有一个条形码扫描仪.当页面加载时,我将代码中的焦点设置到文本框中,因此我可以根据条形码扫描仪结果从代码中设置文本框中的文本.用户几乎不需要在此字段中键入内容.因此,我不需要或不想让键盘显示和占用空间.在极少数情况下,我确实允许他们仍然手动输入文本,例如,在条形码无法读取的情况下.然后他们会选择应该再次设置焦点的控件(即使它可能已经以编程方式获得焦点),而是将焦点设置为光标、触摸或其他东西,然后我想显示软键盘.

Second, related to setting focus. I have a text box on my UI that I set control to with the same Programmatic focus call I listed above. However, the soft (on screen)keyboard shows when this happens. I dont want it to show up when I set focus Programmatically but then have it show if the user selects the field. The scenario is I have a barcode scanner. When the page loads, I set focus in code to the text box and it is therefore ready for me to set the text in the text box from code, based on the barcode scanner result. There is hardly ever a need for the user to type into this field. Therefore, I dont need or want to have the keyboard showing and taking up real estate. There is a rare case when I do allow them to still type the text in manually, for example, in the case the barcode does not read. They would then select the control (even though it may already have focus programmatically) which should set focus again but instead as cursor, touch or something and then I want to show the soft keyboard.

最好的方法是什么?

谢谢!

推荐答案

我认为调用 Focus() 的最佳位置是在同一控件的 Loaded 事件处理程序中你试图集中.当此控件完全加载时,意味着它已准备好进行交互,包括聚焦.

I think the best place to call Focus() is in Loaded event handler of the same control which you trying to focus. When this control is fully loaded, it means it's ready for interaction, including focusing.

为了防止出现屏幕键盘,TextBox 类具有 PreventKeyboardDisplayOnProgrammaticFocus 属性.尝试将其设置为 true,这应该可以解决您的问题.

As for preventing on-screen keyboard to appear, the TextBox class has PreventKeyboardDisplayOnProgrammaticFocus property. Try to set it to true, this should solve your issue.

这篇关于即使我将焦点设置为控件,Windows 10 uwp 也会隐藏软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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