Scrolling horizontally in Xamarin.Forms ScrollView

I use Xamarin.Forms and created a ScrollView that contains a horizontal StackLayout. I want to scroll horizontally, so I set:

Orientation = ScrollOrientation.Horizontal; 

But I do not get a horizontal scroll. StackLayout content is wider than the screen, and I see that the content is cropped around the edge.

How to achieve horizontal scrolling with Xamarin.Forms?

+8
xamarin.forms
source share
2 answers

That's how I got it to work

  var scrollView = ScrollView { HorizontalOptions = LayoutOptions.Fill, Orientation = ScrollOrientation.Horizontal, Content = new StackLayout{ Orientation = StackOrientation.Horizontal, Children = {} } }; 
+12
source share

If you use templates in Visual Studio 2013 for Xamarin applications, the version of Xamarin.Forms is a bit outdated and does not support scrolling. To fix this, just nuget 'update-package' and this code

 public class MainPage : ContentPage { public MainPage() { Label label = new Label { Text = "This is a very long label which I expect to scroll horizontally because it in a ScrollView.", Font = Font.SystemFontOfSize(24), }; this.Content = new ScrollView { Content = label, Orientation = ScrollOrientation.Horizontal, }; } } 

The code works great on Android.

For iOS, the code will work properly.

Unfortunately, for the date, for WP8 there is an error and the hack is to add a custom renderer.

 using System.Windows.Controls; using App2.WinPhone; using Xamarin.Forms; using Xamarin.Forms.Platform.WinPhone; [assembly: ExportRenderer(typeof(ScrollView), typeof(FixedSVRenderer))] namespace App2.WinPhone { public sealed class FixedSVRenderer : ScrollViewRenderer { protected override void OnModelSet() { base.OnModelSet(); if (Model.Orientation == ScrollOrientation.Horizontal) { // Enable horiz-scrolling Control.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; } } } } 
0
source share

All Articles