2017-05-02 120 views
0

我使用的Visual Studio 2017年,我創建了便攜式類庫共享項目,我加入到MainPage.xaml.cs中的類文件下面的代碼,Xamarin.form滾動型不工作

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 ;  

然後我部署了該項目,並在本地機器上運行它,發現滾動不起作用。 我在這裏錯過了什麼? 請任何幫助。 謝謝。

回答

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; 
+0

您可以使用XAML來做到這一點嗎?我試圖用XAML來做到這一點。但它不起作用。 – Curiousity

+1

當然,所有代碼都可以通過XAML來實現,反之亦然。 –

+0

我的XAML就是這樣。 ........。但它不是在Android上滾動。你能告訴我我是否失去了什麼? – Curiousity

0

試試這個

VAR堆棧=新StackLayout();

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

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

Content = new ScrollView {Content = stack}