How move the scroll only when there are the keyboard

亡梦爱人 提交于 2020-05-15 05:48:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!