真的有一种方法可以使用Xamarin Forms中提供的元素列表使旋转木马视图在循环中循环吗



我使用的是CarouselView.FormsPlugin V5.2.0 下面还附上了我的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类中,只有我编写了itemssoource列表"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.forms5.0.0.1487-pre1中测试时。在CarouselView中添加了一个新的loop属性。

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

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

CarouselView未循环

[Spec]旋转木马查看

最新更新