问题
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:
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.
来源:https://stackoverflow.com/questions/61279486/how-move-the-scroll-only-when-there-are-the-keyboard