Turn off soft keyboard in uwp app for windows

五迷三道 提交于 2019-12-01 23:18:34

I'm not sure if there is a direct way to prevent keyboard from showing up. You can surely hide the keyboard once it shows, by subscribing to InputPane's events:

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

But this doesn't look nice. Therefore I've tried a tricky way to achieve what you want - disable the TextBox for hit testing and use dummy control under it to set programmatic focus. As I've tested it should work. The sample 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>

And the code behind:

private void Border_Tapped(object sender, TappedRoutedEventArgs e)
{
    myTextBox.Focus(FocusState.Programmatic);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!