You'll need to create a dependency service and listen to the event that is called when the keyboard appears. You can set up the dependency service like this:
IKeyboard.cs (in your PCL project):
public interface IKeyboard
{
event EventHandler<EventArgs> KeyboardShowing;
event EventHandler<EventArgs> KeyboardHiding;
void HideKeyboard();
}
Keyboard_UWP.cs (in your UWP project):
public class Keyboard_UWP : IKeyboard
{
private InputPane _inputPane;
public event EventHandler<double> KeyboardShowing;
public event EventHandler<EventArgs> KeyboardHiding;
public KeyboardVisibility_UWP()
{
_inputPane = InputPane.GetForCurrentView();
_inputPane.Showing += OnInputPaneShowing;
_inputPane.Hiding += OnInputPaneHiding;
}
private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardShowing?.Invoke(this, null);
}
private void OnInputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
KeyboardHiding?.Invoke(this, null);
}
public void HideKeyboard()
{
_inputPane.TryHide();
}
}
Then in your PCL, you can listen to when it shows:
DependencyService.Get<IKeyboard>().KeyboardShowing += OnKeyboardShowing();
private void OnKeyboardShowing(object sender, EventArgs e)
{
if (you want to hide the keyboard)
DependencyService.Get<IKeyboard>().HideKeyboard();
}