简体   繁体   中英

Xamarin.form Scrollview is not working

I am using visual studio 2017, I created a shared project with portable class library, I added the following code in to MainPage.xaml.cs class file,

var scroll = new ScrollView();
Content = scroll;
var stack = new StackLayout();

stack.Children.Add(new BoxView { BackgroundColor = Color.Red,   HeightRequest = 600, WidthRequest = 600 });

stack.Children.Add(new Entry());

content=stack ;    

then I deployed the project, and run it in local machine, I found that the scrolling is not working. what am I missing in here? Any help please. Thanks.

You're not adding the stack to the scroll. Edit it like this:

var scroll = new ScrollView();
var stack = new StackLayout();

stack.Children.Add(new BoxView { BackgroundColor = Color.Red,   HeightRequest = 600, WidthRequest = 600 });

stack.Children.Add(new Entry());

// Note how I add the stack object to the ScrollView here
scroll.Content = stack;

// And add the ScrollView to the Content of the page instead of the stack
Content = scroll;

Try this

var stack = new StackLayout();

stack.Children.Add(new BoxView { BackgroundColor = Color.Red, HeightRequest = 600, WidthRequest = 600 });

stack.Children.Add(new Entry());

Content = new ScrollView { Content = stack }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM