简体   繁体   English

从Windows App C#隐藏虚拟键盘

[英]Hide Virtual Keyboard from Windows App C#

I am new in UWP, I want to hide On screen keyboard which pops up on focus on textbox.I already have numeric pad to accept the input from user. 我是UWP的新手,我想隐藏屏幕键盘,该键盘会弹出显示在文本框上的焦点。我已经有了数字键盘来接受用户的输入。 How to avoid keyboard's automatic functionality. 如何避免键盘的自动功能。

Tried with PreventKeyboardDisplayOnProgrammaticFocus="True" and InputPane.GetForCurrentView().Showing += (s, e) => (s as InputPane).TryHide(); 尝试使用PreventKeyboardDisplayOnProgrammaticFocus="True"InputPane.GetForCurrentView().Showing += (s, e) => (s as InputPane).TryHide();

but no use. 但没有用。

You can set PreventKeyboardDisplayOnProgrammaticFocus on TextBox to True , this can solve your problem. 您可以将TextBox上的PreventKeyboardDisplayOnProgrammaticFocus设置为True ,这可以解决您的问题。

Update 更新资料

When the user clicks on the TextBox, the FocusState of the space is Pointer , not Programmatic , so the PreventKeyboardDisplayOnProgrammaticFocus property does not work. 当用户单击TextBox时,空间的FocusStatePointer ,不是Programmatic ,因此PreventKeyboardDisplayOnProgrammaticFocus属性不起作用。

This is a Hack method that achieves your purpose through visual spoofing: 这是一种Hack方法,可以通过视觉欺骗来实现您的目的:

<Grid>
    <TextBox x:Name="HideTextBox" Width="1" Height="1" PreventKeyboardDisplayOnProgrammaticFocus="True"/>
    <TextBox x:Name="ShowTextBox" GotFocus="ShowTextBox_GotFocus" IsReadOnly="True" Text="{Binding ElementName=HideTextBox,Path=Text}"/>
</Grid>

code-behind: 后台代码:

private void ShowTextBox_GotFocus(object sender, RoutedEventArgs e)
{
    HideTextBox.Focus(FocusState.Programmatic);
}

As you can see, when ShowTextBox is set to ReadOnly, it does not trigger the virtual keyboard. 如您所见,将ShowTextBox设置为ReadOnly时,它不会触发虚拟键盘。 When it gets the focus, we programmatically shift the focus to the "hidden" HideTextBox . 当获得焦点时,我们以编程方式将焦点转移到“隐藏的” HideTextBox At this time, the virtual keyboard will be intercepted. 这时,虚拟键盘将被拦截。 User-entered content can be obtained by binding. 可以通过绑定获得用户输入的内容。

It's not perfect, I also look forward to a better way to solve this problem. 这不是完美的,我也期待有更好的方法来解决这个问题。

Best regards. 最好的祝福。

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

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