0

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. How to avoid keyboard's automatic functionality.

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

but no use.

Brijesh
  • 91
  • 1
  • 14
  • Possible duplicate of [Windows 10 uwp hide soft keyboard even when I set focus to a control](https://stackoverflow.com/questions/41754904/windows-10-uwp-hide-soft-keyboard-even-when-i-set-focus-to-a-control) – Pavel Anikhouski Aug 01 '19 at 09:53

1 Answers1

1

You can set PreventKeyboardDisplayOnProgrammaticFocus on TextBox to True, this can solve your problem.

Update

When the user clicks on the TextBox, the FocusState of the space is Pointer, not Programmatic, so the PreventKeyboardDisplayOnProgrammaticFocus property does not work.

This is a Hack method that achieves your purpose through visual spoofing:

<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. When it gets the focus, we programmatically shift the focus to the "hidden" 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.

Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • already tried...it is working on loaded...But when user starts tapping on the textbox it starts showing..i think on user interaction its not working.. – Rohini Tribhuwan Aug 02 '19 at 03:56
  • Yes, there are many ways for the TextBox to get the focus. `PreventKeyboardDisplayOnProgrammaticFocus` can only prevent the programmatically getting the focus. I can't seem to do it in UWP by simply changing the properties, but there are also some ways to achieve this. See my update answer – Richard Zhang Aug 02 '19 at 10:07