3
votes

I used this function to move my scroll, but this function is activated when I don't have a keyboard, I only want to use it when there is a keyboard, how can I solve this?

<Entry    Placeholder="entry" Focused="EntryKeyboardHandle_Focused"

void EntryKeyboardHandle_Focused(object sender, FocusEventArgs e)
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                    await Task.Delay(10);
                    await MainScroll.ScrollToAsync(0, 100, true);
            });
        }

I found this thread Xamarin forms check if keyboard is open or not

I have my entry with name "Entry" and in my code behind Entry.Focused += keyboardService.KeyboardIsShown; but I get this error.

The event 'IKeyboardService.KeyboardIsShown' can only appear on the left hand side of += or -=

1
There is already a thread with this [stackoverflow.com/questions/46360257/…Alen.Toma
@Alen.Toma but how can i use that var keyboardService = Xamarin.Forms.DependencyService.Get<IKeyboardService>(); ?mikkylekyle
the thread already tell you how, you create two classes for IOS and android called KeyboardService Then you use them with DependencyService.Alen.Toma
@Alen.Toma thanks, but i get error, cannot find the interfacemikkylekyle
What is the errorAlen.Toma

1 Answers

2
votes

ok accourding to the thread that you found you could try this code.

in the contructor add this code

private bool _keyboardIsOn;

cto(){
 // Initio
 keyboardService.KeyboardIsShown += (sender, e){ _keyboardIsOn = true; }
 keyboardService.KeyboardIsHidden += (sender, e){ _keyboardIsOn = false; }
}

No you could check if _keyboardIsOn and add your coditions.