0

What the best way (preferably cross-platform) to dismiss keyboard when user starts scrolling sfListView in Xamarin project for IOS and Android? If no cross-platform solution exists - would be glad to hear solutions for both IOS and Android separately. Thank you in advance

JohnDiGriz
  • 171
  • 13

1 Answers1

0

When looking into documention of sfListView, you can find the Identifying scroll state changes part, so you can dismiss keyboard in this event:

listView.ScrollStateChanged += ListView_ScrollStateChanged;

private void ListView_ScrollStateChanged(object sender, ScrollStateChangedEventArgs e)
{
    if (e.ScrollState != ScrollState.Idle)
    {
        //dismiss keyboard
        DependencyService.Get<IKeyboardHelper>().HideKeyboard();
    }
}

To dismiss the keyboard, you have to use DependencyService:

You can use the code in this thread.

Note: Remember to add this line before the start of the namespace in each of your KeyboardHelper classes or the DependencyService will not find them.

[assembly: Xamarin.Forms.Dependency(typeof(xxxxxxKeyboardHelper))] 
nevermore
  • 15,432
  • 1
  • 12
  • 30