Xamarin Forms: Keyboard didn't hide

The keyboard hides when I create the page, but when I change the focus to another entry I call the same function but the soft keyboard didn't hide?

ConfigService.cs

    public void HideKeyboard()
    {
        var inputMethodManager = Xamarin.Forms.Forms.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
        if (inputMethodManager != null && Xamarin.Forms.Forms.Context is Activity)
        {
            var activity = Xamarin.Forms.Forms.Context as Activity;
            var focusedView = activity.CurrentFocus;
            var token = focusedView == null ? null : focusedView.WindowToken;
            inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);
        }
    }

VerplaatsingPage.xaml.cs

namespace SI_Foodware.View
{
   public partial class VerplaatsingPage : ContentPage
   {
    VerplaatsingPageViewModel vm;

    public VerplaatsingPage (SubMenu subMenu)
    {
        InitializeComponent ();

        vm = new VerplaatsingPageViewModel(this, subMenu);
        BindingContext = vm;
    }

    public void OnClickDestination(object o, EventArgs e)
    {

    }

    public void OnClickSelect(object o, EventArgs e)
    {

    }

    public void OnClickCancel(object o, EventArgs e)
    {

    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        ent_drager.Focus();
        IConfigService configService = DependencyService.Get<IConfigService>();
        configService.HideKeyboard();    
    }
}
}

VerplaatsingPageViewModel.cs

    public void Keyboard()
    {
        IConfigService configService = DependencyService.Get<IConfigService>();
        configService.HideKeyboard();
    }


    public void OnScan(string scanProperty)
    {
        var list = db.GetAllItems<ContainerLine>();
        Artikel = list[0].ItemNo;
        Description = list[0].Description;
        LotNo = list[0].LotNo;
        NumberOfContainer = list[0].Quantity;
        KiloDrager = list[0].KgQuantity;
        UnitOfMeasure = list[0].UnitofMeasureCode;
        LocationFrom = list[0].BinCode;

        cp.FindByName<Entry>("ent_destination").Focus();
        Keyboard(); <-- Doesn't Work 
    }
Sign In or Register to comment.