Search code examples
androidiosxamarin.formskeyboardscrollview

How can I make Xamarin.Forms Scroll view NOT push content off screen?


I am posting and answering my own question because this issue took me days and days to figure out, and finally I did some half-baked kludge, and then months later I found the actual answer, and I want to spare others that.

Problem: to get iOS text entry elements to scroll up and stay visible when a keyboard appears, in Xamarin Forms the easiest way is to use a ScrollView, BUT for some reason any time you use a ScrollView the dang thing resizes its content so that some of it is slightly off screen.

Content not inside ScrollView:

enter image description here

Content inside ScrollView:

enter image description here

As you can see, for some darn reason the ScrollView has its own opinion about how to lay out its contents, and that opinion is that some of it should always be off-screen.

What the heck? I've tried changing layouts and using different kinds of nesting views and adjusting layout options and margins and everything I could think of. The dang layout just always changes without me telling it to!

How do I make it behave?


Solution

  • ScrollView has an Orientation setting to determine the directions it can scroll. You can set it to Neither right there in the XAML, and all your content will be back where it should be.

    Note that if you actually want scrolling behavior, this will mess that up. But if you're only using a ScrollView to get its nice behavior around keyboards appearing and disappearing, as I usually am, that shouldn't matter.