繁体   English   中英

真的有办法让 carouselview 循环使用 Xamarin Forms 中提供的元素列表吗?

[英]Is there really a way to make carouselview to loop in a cycle with the list of elements provided in Xamarin Forms?

我正在使用 V5.2.0 的 CarouselView.FormsPlugin还在下面附上我的 xaml carouselview 代码:

<cv:CarouselViewControl x:Name="cv"
    ItemsSource="{Binding MyItemsSource}"
    ShowArrows="true"
    ShowIndicators="true"
                        IndicatorsShape="Circle"
                        CurrentPageIndicatorTintColor="CornflowerBlue"
                        PositionSelectedCommand="{Binding MyCommand}"
    PositionSelected="Handle_PositionSelected"
    Scrolled="Handle_Scrolled"
    Orientation="Horizontal"
                        AnimateTransition="True"
                        ArrowsBackgroundColor="LightGray"
                        IsSwipeEnabled="True" Grid.Row="0">
</cv:CarouselViewControl>

在 xaml.cs 文件中绑定 MainViewModel 如下: 在 MainViewModel 类中,我只编写了 itemssource 列表“MyItemsSource”列表。

BindingContext = _vm = new MainViewModel();

MainViewModel 类如下:

 public class MainViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public MainViewModel()
    {
        MyItemsSource = new View[]
        {
            new Image() { Source = ImageSource.FromResource("MobileShop.DashboardImages.Dimage1.jpg"), Aspect = Aspect.AspectFit },
            new Image() { Source = ImageSource.FromResource("MobileShop.DashboardImages.Dimage2.jpg"), Aspect = Aspect.AspectFit },
            new Image() { Source = ImageSource.FromResource("MobileShop.DashboardImages.Dimage3.jpg"), Aspect = Aspect.AspectFit },
            new Image() { Source = ImageSource.FromResource("MobileShop.DashboardImages.Dimage4.jpg"), Aspect = Aspect.AspectFit },
            new Image() { Source = ImageSource.FromResource("MobileShop.DashboardImages.Dimage5.jpg"),  Aspect = Aspect.AspectFit }
        };

        MyCommand = new Command(() =>
        {
            Debug.WriteLine("Position selected.");
        });
    }

    IEnumerable<View> _myItemsSource;
    public IEnumerable<View> MyItemsSource
    {
        set
        {
            _myItemsSource = value;
            OnPropertyChanged("MyItemsSource");
        }
        get
        {
            return _myItemsSource;
        }
    }

    public Command MyCommand { protected set; get; }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

现在在轮播视图中一切正常。 但是当我在到达项目末尾后尝试向右或向左滑动时,它没有滑动。 也就是说,我有五个项目,我可以向左滑动以转到第五个项目,反之亦然。 但是到达第五项后,我无法向左滑动,也无法在第一项中向右滑动。 在此先感谢您的帮助!!

此功能尚未实现。

当我在 Xamarin.forms 5.0.0.1487-pre1测试时。 CarouselView添加了一个新的loop属性。

所以我相信这个功能可能会在下一个 5.0 版本中发布。

也可以通过 Github 的相关 issue 找到一些信息。

CarouselView 不循环

[规格] CarouselView

暂无
暂无

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

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