Nếu bạn đang sử dụng các mẫu trong Visual Studio 2013 cho các ứng dụng Xamarin, phiên bản của Xamarin.Forms là một chút lỗi thời và không hỗ trợ di chuyển. Để khắc phục điều này, chỉ cần cập nhật gói 'nuget' và mã này
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's in a ScrollView.",
Font = Font.SystemFontOfSize(24),
};
this.Content = new ScrollView {
Content = label,
Orientation = ScrollOrientation.Horizontal,
};
}
}
mã này sẽ hoạt động tốt trên Android.
Đối với iOS, mã sẽ làm việc như mong đợi.
Thật không may, vào ngày, cho WP8 có một lỗi và hack là thêm một renderer tùy chỉnh.
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;
}
}
}
}
Nguồn
2014-11-25 04:39:18
Bạn có thể đăng mã để tạo ScrollView và đặt Nội dung của nó bằng StackLayout không? – Pedro