简体   繁体   English

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

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

I have a CarouselView and I want to have some animation after Items are scrolled manually (by swiping left or right on CarouselView).我有一个CarouselView ,我想在手动滚动项目后有一些动画(通过在 CarouselView 上向左或向右滑动)。 I want to know when the scroll animation is complete or ended.我想知道滚动动画何时完成或结束。 Is there any way, I did not find anything related to this in the Official Docs.有什么办法,我在官方文档中没有找到与此相关的任何内容。

Here is my code这是我的代码

<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>

As far as I know, use CurrentItemChanged instead of Scrolled property of CarouselView .据我所知,使用CurrentItemChanged而不是CarouselViewScrolled属性。

Change your XAML as将您的 XAML 更改为

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

If you want to get current Item after Swiping to a new Item use carouselView.Position .如果您想在滑动到新项目后获取当前项目,请使用carouselView.Position

In your C# Code behind在你的 C# 代码后面

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

Refer this for Official Documentation 请参阅此官方文档

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

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