首页 > 解决方案 > 真的有办法让 carouselview 循环使用 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));
    }
}

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

标签: c#androidiosvisual-studioxamarin.forms

解决方案


此功能尚未实现。

当我在 Xamarin.forms 中进行测试时5.0.0.1487-pre1。有一个新loop属性添加到CarouselView

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

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

CarouselView 不循环

[规格] 轮播视图


推荐阅读