我有一个简单的屏幕示例,试图实现ScrollToAsync函数。我根本不能让这个函数滚动。
我的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调用,所以我可以在它之前使用“等待”,但这是行不通的。
发布于 2019-03-28 12:49:35
这是因为滚动卷尚未加载,最好尝试将此方法添加到代码中。
protected override void OnAppearing()
{
base.OnAppearing();
scLista.ScrollToAsync(0,100,false);
}发布于 2019-08-15 22:39:42
添加Delay会对您有所帮助,我在计时器中设置了它,并为我工作得很好。
public MainPage()
{
InitializeComponent();
StarAnimate();
}
private void StarAnimate()
{
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
myScroll.ScrollToAsync(LatestElment, ScrollToPosition.Center, true);
return false;
});
}延迟元素:要滚动的元素。
https://stackoverflow.com/questions/52231283
复制相似问题