【问题标题】:How to detect scroll completed or end after scrolling in CarouselView in Xamarin Forms?如何在 Xamarin Forms 的 CarouselView 中滚动后检测滚动完成或结束?
【发布时间】:2021-07-09 15:31:50
【问题描述】:

我有一个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>

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

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

    将您的 XAML 更改为

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

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

    在你的 C# 代码后面

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

    Refer this for Official Documentation

    【讨论】:

      猜你喜欢
      • 2012-10-30
      • 2011-04-27
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2011-01-06
      • 1970-01-01
      相关资源
      最近更新 更多