我正在使用visual studio 2017,我创建了一个带有可移植类库的共享项目,我将以下代码添加到MainPage.xaml.cs类文件中,
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 ;
然后我部署了项目,并在本地机器上运行它,我发现滚动不起作用。 我在这里错过了什么? 请帮忙。 感谢。
答案 0 :(得分:1)
您没有将stack
添加到滚动条中。像这样编辑:
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;
答案 1 :(得分:0)
试试这个
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}