如何在 Visual Studio 2019 4.4+ 和 Xamarin.Forms 中使用 CarouselView?

How to use CarouselView in Visual Studio 2019 4.4+ and Xamarin.Forms?

我将 Xamarin.Forms 版本从 3.4.0.1 更新到最新版本:4.4.0.991477,但是我之前使用的 CarouselView Xamarin.Forms.CarouselView 不再工作了,我明白了错误:

The type 'CarouselView' exists in both 'Xamarin.Forms.CarouselView, 
Version=1.0.7.0, Culture=neutral, PublicKeyToken=null' and
'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'

我找遍了 Xamarin.Forms.CarouselView 的解决方案和替代品,但我见过的最好的插件是 Alex Rainman 的插件,CarouselView.FormsPlugin、https://github.com/alexrainman/CarouselView,但我我读过人们抱怨该插件中的一些错误。

我也听说Xamarin Forms现在有自己的新插件了? https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/ 但是它很新而且没有人谈论它,根本没有太多文档...

那么..对于当前 Xamarin.Forms 开发人员 (4.4+),您现在使用什么来实现 CarouselViews? CarouselView.FormsPlugin值得信赖吗? (我必须为一家大公司更新旧的CarouselView,所以我需要在推送更新版本之前确保它是好的)。

编辑:卸载插件后: 我现在遇到无法解决问题:'Xamarin.Forms.CarouselView, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' 错误。

我猜是因为我有这条线

xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView" 在我的 xaml 文件中,但是如果我把它拿出来,那么我的代码使用 CarouselView

<cv:CarouselView 
  VerticalOptions="FillAndExpand" 
                   HorizontalOptions="FillAndExpand"
                   ItemsSource="{Binding ReadingList}" 
                   Position="{Binding Position}">
    <cv:CarouselView.ItemTemplate>
...

被弄乱了

编辑 2:我认为我需要将 cv:____ 更改为其他内容,因为它显然不再使用相同的插件,所以我尝试从两者中删除 cv: 并且它有效..是对吗?

I figured that I needed to change cv:____ to something else because it obviously isn't using the same plugin anymore, so I tried removing the cv: from both and it worked.. is that right?

是的,你做的是对的。

在 Xamarin.forms 4.4.0.991477 中,CarouselView Namespace: Xamarin.FormsAssembly:Xamarin.Forms.Core.dll 中的 class。

因此您可以将 cv___ 修改为:

xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Core"

并像这样使用它:

<cv:CarouselView/>

一般不需要使用cv,因为the default namespace已经指定XAML文件中定义的没有前缀的元素是指Xamarin.Forms classes:

xmlns="http://xamarin.com/schemas/2014/forms"

因此,在您从两者中删除 cv: 并且您的项目工作正常后。