I found what seems to be useful in this link:
A Keyboard disabled Entry control in Xamarin Forms
But it seems that it only works in Xamarin Forms. I even used it in my MAUI app, but it simply has no effect !
The reason I am looking to do this is because I want to enable focus on the Editor field but without triggering the soft keyboard (for a barcode scanner field)
Thanks.
it's more simple than you think :)
private void SingInButton_Clicked(object sender, EventArgs e)
{
//Trick To Hide VirtualKeyboard
PasswordEntry.IsEnabled = false;
PasswordEntry.IsEnabled = true;
}
}
Well, in MAUI there's not such need to create an interface...
Just add in Platforms/Android/KeyboardHelper.cs
using Android.Content;
using Android.View.InputMethods;
namespace ApplicationName.Platforms
{
public static partial class KeyboardHelper
{
public static void HideKeyboard()
{
var context = Platform.AppContext;
var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null)
{
var activity = Platform.CurrentActivity;
var token = activity.CurrentFocus?.WindowToken;
inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
activity.Window.DecorView.ClearFocus();
}
}
}
}
And in Platforms/iOS/KeyboardHelper.cs
using UIKit;
namespace ApplicationName.Platforms
{
public static partial class KeyboardHelper
{
public static void HideKeyboard()
{
UIApplication.SharedApplication.Delegate.GetWindow().EndEditing(true);
}
}
}
And that's it.
Then in your application just call:
Platforms.KeyboardHelper.HideKeyboard();
to call the function. The class that will be run depends on the platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With