The xamarin.forms scroll keyboard will appear and the scroll button will also

Hi, I have a strange problem.

I defined several labels and a text box for the purpose of data entry using xamarin.forms. I wrapped them in a scroll so that when the keyboard appears they should scroll.

It is working fine. A control that has focus is scrolled up and the keyboard appears when it is focused. but I also have some buttons at the bottom of my form. Now the problem is that whenever the keyboard appears, my bottom buttons also scroll. which looks weird. As a button to send or cancel, it should stay down there.

the following is my code:

var firstNameLabel = new Label { HorizontalOptions = LayoutOptions.Fill }; firstNameLabel.Text = "First Name"; var firstName = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand }; firstName.SetBinding (Entry.TextProperty,MyViewModel.FirstNamePropertyName); var lastNameLabel = new Label { HorizontalOptions = LayoutOptions.Fill}; lastNameLabel.Text = "Last Name"; var lastName = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand }; lastName.SetBinding (Entry.TextProperty, MyViewModel.LastNamePropertyName); ---- other fields Button btnSubmit = new Button { HorizontalOptions = LayoutOptions.Fill, BackgroundColor = Color.FromHex("#22498a"), TextColor = Color.White, Text = "Submit" }; var cancelButton = new Button { Text = Cancel", BackgroundColor = Color.FromHex("0d9c00"), TextColor = Color.White }; contactUsButton.Clicked += (object sender, EventArgs e) => { // cancel operation }; var cotrolStakeLayout = new StackLayout () { Padding = new Thickness(Device.OnPlatform(5, 5, 5),0 , Device.OnPlatform(5, 5, 5), 0), //new Thickness(5,0,5,0), VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.Fill, Orientation = StackOrientation.Vertical, Children = { firstNameLabel, firstName, lastNameLabel, lastName, -- and other fields} }; var scrollableContentLayout = new ScrollView (){ Content = cotrolStakeLayout, Orientation = ScrollOrientation.Vertical, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill }; var buttonLayout = new StackLayout (){ Padding = new Thickness(Device.OnPlatform(5, 5, 5),0 , Device.OnPlatform(5, 5, 5), 0), //new Thickness(5,0,5,0), HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Orientation = StackOrientation.Vertical, Children= { btnSubmit , cancelButton } }; var nameLayout = new StackLayout() { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Orientation = StackOrientation.Vertical, Children = {scrollableContentLayout,buttonLayout} }; return nameLayout; 

Any ideas what is wrong with him?

+1
source share
1 answer

You must change your layout to achieve your goal:
- Define "Main-StackLayout"
- Create a "Button-StackLayout" for your buttons (which should stay on top)
- Add your buttons to "Button-StackLayout"
- Add a StackLayout button to the "Main-StackLayout"
- Add ScrollView to "Main-StackLayout"
- Set page content to "Main-StackLayout"
This should work: the buttons stay on top, where (only) you can scroll the ScrollView.

0
source

Source: https://habr.com/ru/post/1204043/


All Articles