0

I have a TextBox and a Button. When the button is clicked, the TextBox loses focus and the keyboard hides. How do I keep the keyboard from hiding when the button is clicked?

I first thought to use AllowFocusOnInteraction, but this is not supported on Android at this time.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
Kyle M
  • 23
  • 4

2 Answers2

1

Although AllowFocusOnInteraction isn't implemented, Control.IsTabStop is. IsTabStop likewise prevents the control from receiving focus. Use IsTabStop instead.

David Oliver
  • 2,251
  • 12
  • 12
0

Uno Platform is using the Android input behavior here, so when the input loses focus, the programmatic keyboard automatically disappears. However, if you want to show it again immediately, you can give it focus again from within the button Click handler.

XAML:

<TextBox x:Name="InputBox" />
<Button Click="TestClick">Test</Button>

C#:

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

The input pane starts disappearing, but is immediately requested again, so it is almost imperceptible.

You can also try to trigger the soft keyboard programmatically without having any TextBox in place, by writing platform-specific code. This SO question for example includes quite a few solutions for Android. In general, they utilize the INPUT_METHOD_SERVICE and call ShowSoftInput on it.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • 1
    Thank you for the info! I was previously giving focus back to the TextBox, but it would make the keyboard jitter. Using IsTabStop seems like the most straightforward to overcome this at this time. – Kyle M Apr 08 '21 at 15:18