C# ScrollView滚动位置更新太晚
我有一个CarouselView,它根据正在查看的项目更改其ItemTemplate:C# ScrollView滚动位置更新太晚,c#,xaml,xamarin,scrollview,C#,Xaml,Xamarin,Scrollview,我有一个CarouselView,它根据正在查看的项目更改其ItemTemplate: <!--Alarm Event UI--> <CarouselView x:Name="cvAlarmEvents" ItemsSource="{Binding AlarmEvents}" CurrentItem="{Binding Sel
<!--Alarm Event UI-->
<CarouselView x:Name="cvAlarmEvents"
ItemsSource="{Binding AlarmEvents}"
CurrentItem="{Binding SelectedAlarmEvent}"
CurrentItemChangedCommand="{Binding CmdSelectedAlarmEventChanged}"
ItemTemplate="{StaticResource AlarmEventDataTemplateSelector}"
Grid.Row="2"
Margin="0, 2, 0, 0"
BackgroundColor="#141d3d"
IsVisible="true"
Scrolled="CvAlarmEventsOnScrolled" />
问题是,它不会更新,直到用户滚动回上一个项目,在这一点上,用户可以看到滚动位置重置发生,这不是我想要的。在用户回滚到它之前,应该重置它。这是我目前的尝试,它根本不起作用。有时它可以工作,可能是1/5次,但它并不一致。我尝试过在主线程上调用它并强制布局
private async void OnScrollReset(object sender, Events.ScrollEventArgs e)
{
if (scrollAe.ScrollY > 0)
{
Device.BeginInvokeOnMainThread(async() =>
{
await scrollAe.ScrollToAsync(0, 0, false);
});
scrollAe.ForceLayout();
}
}
ScrollView类派生自Layout类,您不应该将ScrollView放入CarouseView。ScrollView对象不应该与其他提供滚动的控件嵌套。我知道这一点,我在问题中已经提到了。你能分享一个关于这个问题的演示吗,我不能以1/5倍的速度制作这个问题。
ScrollToAsync(0, 0, false);
private async void OnScrollReset(object sender, Events.ScrollEventArgs e)
{
if (scrollAe.ScrollY > 0)
{
Device.BeginInvokeOnMainThread(async() =>
{
await scrollAe.ScrollToAsync(0, 0, false);
});
scrollAe.ForceLayout();
}
}