gpt4 book ai didi

uwp - 关闭 Windows 版 uWP 应用中的软键盘

转载 作者:行者123 更新时间:2023-12-01 16:57:48 26 4
gpt4 key购买 nike

我有一个 uwp 应用程序在运行 Windows 10 的手持设备上运行。手持设备有一个条形码扫描仪,应用程序的所有输入都是使用它进行的。因此,我想防止当用户将焦点移动到任何文本框控件时键盘出现。

在很大程度上,焦点是通过编程方式处理的 - 我已经使用 PreventKeyboardDisplayOnProgrammaticFocus=True 阻止了键盘在这些情况下出现。但用户有时确实需要自己移动焦点,而我找不到任何方法来阻止他这样做时键盘出现。

我找到了有关上述编程焦点的文章,以及当用户在文本框中按 Enter 键时隐藏键盘 - 并将控件的只读值设置为 true 的文章。但这些不适用于本例。我希望能够防止它出现在这个应用程序中。谁能给点建议吗?

最佳答案

我不确定是否有直接的方法来阻止键盘显示。您当然可以通过订阅InputPane的事件来隐藏键盘显示后的情况:

InputPane.GetForCurrentView().Showing += (s, e) => (s as InputPane).TryHide();

但这看起来不太好。因此,我尝试了一种棘手的方法来实现您想要的效果 - 禁用 TextBox 进行 HitTest 并使用其下的虚拟控件来设置编程焦点。正如我测试过的,它应该可以工作。示例 xaml:

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Border Tapped="Border_Tapped" Background="Transparent">
<TextBox x:Name="myTextBox" Width="200" Height="100" Header="Enter:" PreventKeyboardDisplayOnProgrammaticFocus="True" IsHitTestVisible="False"/>
</Border>
<Button Margin="20" Content="Dummy to test focus"/>
</StackPanel>

以及背后的代码:

private void Border_Tapped(object sender, TappedRoutedEventArgs e)
{
myTextBox.Focus(FocusState.Programmatic);
}

关于uwp - 关闭 Windows 版 uWP 应用中的软键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41598350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com