我正在使用 CarouselView 来显示某些页面。
集合是这样定义的。
public IList<View> Pages { get; } = new ObservableCollection<View>();
绑定在 xaml 代码中如下所示。
<CarouselView x:Name="PageCarousel" ItemsSource="{Binding Source={x:Reference PagePanelView}, Path=Pages}" IndicatorView="PageCarouselIndicator" Loop="False" VerticalOptions="FillAndExpand" IsScrollAnimated="False">
用户可以使用按钮触发刷新。刷新逻辑只是调用 Pages.Clear() 并再次添加它们。为了保持当前位置,我使用 ScrollTo(int index)。
不幸的是,这并没有按预期工作,因为 CarouselView 在刷新后总是显示第一页。
Xamarin.Forms 版本是 5.0.0.2083。
谢谢。