标签:hang 位置 view erer tor cal and visual llb
<ContentPage.Content> <ScrollView Orientation="Horizontal"> <StackLayout Orientation="Horizontal"> <Label Text="123123123"></Label> </StackLayout> </ScrollView> </ContentPage.Content>
其中有1个比较重要的属性Orientation可以改变滚动方向,如果你想通过代码修改当前滚动条的位置,可以使用scroll.ScrollToAsync方法来实现
如果你不想显示滚动条,那么只能在各自的Android和IOS平台实现
Android平台
[assembly:ExportRenderer(typeof(Xamarin.Forms.ScrollView),typeof(ScrollViewNoRender))] namespace App1.Droid.Render { public class ScrollViewNoRender : ScrollViewRenderer { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (e.OldElement != null) { e.NewElement.PropertyChanged -= NewElement_PropertyChanged; } if (e.NewElement != null) { e.NewElement.PropertyChanged += NewElement_PropertyChanged; } } private void NewElement_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (ChildCount > 0) { GetChildAt(0).HorizontalScrollBarEnabled = false; GetChildAt(0).VerticalScrollBarEnabled = false; } } } }
IOS平台
[assembly:ExportRenderer(typeof(ScrollView),typeof(ScrollViewNoRender))] namespace App1.iOS.Render { public class ScrollViewNoRender : ScrollViewRenderer { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (e.OldElement != null) { e.NewElement.PropertyChanged -= NewElement_PropertyChanged; } if (e.NewElement != null) { e.NewElement.PropertyChanged += NewElement_PropertyChanged; } } private void NewElement_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { this.ShowsHorizontalScrollIndicator = false; this.ShowsVerticalScrollIndicator = false; } } }
标签:hang 位置 view erer tor cal and visual llb
原文地址:https://www.cnblogs.com/jiecaoge/p/10036113.html