我有一個簡單的屏幕示例,試圖實現(xiàn) ScrollToAsync 函數(shù)。我根本無法獲得滾動功能。我的 XAML: <?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.ItemList"><ContentPage.Content> <ScrollView x:Name="myScroll"> <StackLayout> <Label Text="Welcome to Xamarin.Forms!" /> <Label Text="Welcome to Xamarin.Forms!" /> <Label Text="Welcome to Xamarin.Forms!" /> <Label Text="Welcome to Xamarin.Forms!" /> // Many labels to fill space here <Label Text="Welcome to Xamarin.Forms!" /> </StackLayout> </ScrollView></ContentPage.Content></ContentPage>C# 是: [XamlCompilation(XamlCompilationOptions.Compile)]public partial class ItemList : ContentPage{ public ItemList () { InitializeComponent (); myScroll.ScrollToAsync(0, 100, false); }}我究竟做錯了什么?這一定是我需要做的簡單的事情。我已經嘗試將 ScrollToAsync 調用包裝在異步方法中,因此我可以在它之前使用“await”,但這不起作用。
2 回答

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
那是因為滾動尚未加載,最好嘗試將此方法添加到您的代碼中
protected override void OnAppearing()
{
base.OnAppearing();
scLista.ScrollToAsync(0,100,false);
}

白豬掌柜的
TA貢獻1893條經驗 獲得超10個贊
添加延遲會對您有所幫助,我將其設置在計時器中并且對我來說效果很好。
public MainPage()
{
InitializeComponent();
StarAnimate();
}
private void StarAnimate()
{
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
myScroll.ScrollToAsync(LatestElment, ScrollToPosition.Center, true);
return false;
});
}
LatestElment:要滾動的元素。
- 2 回答
- 0 關注
- 523 瀏覽
添加回答
舉報
0/150
提交
取消