Forum Xamarin.Forms

How to dismiss keyboard in WP, when „Enter-Key“ is pressed?

FredyWengerFredyWenger CHInsider ✭✭✭✭✭

Unbelievable, but true:
Since I work with XF, the Keyboard in WP don’ dismiss, when the “Enter-Key” on the soft-keyboad is pressed (while it works without problems on iOS and Android). I also have filled a bug therefore some months ago...

Problem description:
If I have an Entry or a SearchBar on a page, the keyboard is showed, as soon as the Entry/SearchBar has the focus.
The user can type in text and the press the “Enter-Button” on the soft-keyboard… and… nothing happens...(the keyboard is showed until, the user tap on another element on the page)

As this behavior is not usable in a productive App, I have searched by try-and-error and found a workaround, that seems to work.
Add an .Completed-event to your Entry/SearchBar and disable/enable the Entry/SearchBar when the event-fires.
Example-code:

MyEntry.Completed += (sender, e) =>  // Event is fired, when the “Enter-Key” is pressed
{
  if (Device.OS == TargetPlatform.WinPhone) // Do it only for WP (as iOS and Android works)
  {
     MyEntry.IsEnabled = false;  // Disable Entry -> Seems to cause the Keyboard to dismiss
     MyEntry.IsEnabled = true; // Re-enable Entry
  } 
};

Notes:
This is a workaround that seems to work for now...
As soon, as Xamarin have implemented the correct handling, this should be removed from code.

Hope this helps someone…

Posts

Sign In or Register to comment.