繁体   English   中英

如何在 Xamarin Forms 中的 CarouselView 中滚动后检测滚动完成或结束?

[英]How to detect scroll completed or end after scrolling in CarouselView in Xamarin Forms?

我有一个CarouselView ,我想在手动滚动项目后有一些动画(通过在 CarouselView 上向左或向右滑动)。 我想知道滚动动画何时完成或结束。 有什么办法,我在官方文档中没有找到与此相关的任何内容。

这是我的代码

<CarouselView x:Name="carouselView" Scrolled="CarouselViewScrolled" Loop="False" HorizontalOptions="FillAndExpand" >
    <CarouselView.ItemsSource>
        <x:Array Type="{x:Type ContentView}">
            <ContentView>
                <!--Defining View 1-->
            </ContentView>
            <ContentView>
                <!--Defining View 2-->
            </ContentView>
            <ContentView>
                <!--Defining View 3-->
            </ContentView>
    </CarouselView.ItemsSource>
</CarouselView>

据我所知,使用CurrentItemChanged而不是CarouselViewScrolled属性。

将您的 XAML 更改为

<CarouselView x:Name="carouselView" CurrentItemChanged="CarouselViewItemChanged">
...

如果您想在滑动到新项目后获取当前项目,请使用carouselView.Position

在你的 C# 代码后面

void CarouselViewItemChanged(object sender, CurrentItemChangedEventArgs e)
{
    Debug.WriteLine("Position: " + carouselView.Position);
}

请参阅此官方文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM