2017-05-02 3 views
0

ich Visual Studio 2017 verwende ich ein gemeinsames Projekt mit tragbarer Klassenbibliothek erstellt, habe ich den folgenden Code in zu MainPage.xaml.cs KlassendateiXamarin.form Scroll funktioniert nicht

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 ;  

dann Ich habe das Projekt bereitgestellt und auf dem lokalen Computer ausgeführt. Ich habe festgestellt, dass das Scrollen nicht funktioniert. Was fehlt mir hier? Irgendwelche Hilfe bitte. Danke.

Antwort

1

Sie fügen die stack nicht zum Scroll hinzu. Bearbeiten Sie es wie folgt aus:

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

Können Sie dies auch mit XAML tun? Ich habe versucht, dies mit XAML zu tun. Aber es funktioniert nicht. – Curiousity

+1

Sicher, alles Code ist mit XAML möglich und umgekehrt. –

+0

Mein XAML ist so. ......... Aber es scrollt nicht auf Android. Könnten Sie mir bitte sagen, ob ich etwas vermisse? – Curiousity

0

Versuchen Sie, diese

var Stack = new StackLayout();

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

stack.Children.Add (neuer Eintrag());

Inhalt = neue ScrollView {Inhalt = Stapel}

Verwandte Themen