c# - 真的有办法让 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));
}
}
现在在轮播视图中一切正常。但是当我在到达项目末尾后尝试向右或向左滑动时,它不会滑动。也就是说,我有五个项目,我可以向左滑动以转到第五个项目,反之亦然。但是到达第五项后,我无法向左滑动,也无法在第一项中向右滑动。提前感谢您的帮助!!
解决方案
此功能尚未实现。
当我在 Xamarin.forms 中进行测试时5.0.0.1487-pre1
。有一个新loop
属性添加到CarouselView
。
所以我相信这个功能可能会在下一个 5.0 版本中发布。
也可以通过 Github 中的相关 issue 找到一些信息。
推荐阅读
- python - 如何从张量流中的两个二维张量中获取交叉合约矩阵?
- javascript - 如何设置带有撇号和引号的 javascript 变量(无法转义!)
- sql - SQl 查询以减去相同 id 的两行并将差异填充到新列中
- php - 使用 PHP CodeIgniter 在 MYSQL 的单列中插入和获取多封电子邮件?
- c# - 在每个循环内将索引乘以 2
- mongodb - 嵌套数组性能和最佳实践问题中的 MongoDB $lookup
- python - 量化如何以及何时在 TFLite 图中起作用?
- plone - 构建 Plone.4-3.14 给出“需要超过 0 个值才能解压”
- sql-server - SQL Server 2014 中将 varchar 转换为时间失败
- javascript - 如何使用javascript将多个标记连接到一个位置