简体   繁体   中英

CarouselView xamarin forms conflicting Xamarin forms error

I have been working with CarouselView while using the Nuget Package Xamarin.Forms.CarouselView . I have tried to display the images as auto sliding.

XAML

<StackLayout Grid.Row="0" Grid.ColumnSpan="4">
    <cv:CarouselView x:Name="MainCarouselView" Position="{Binding PositionIndex, Mode=TwoWay}">
        <cv:CarouselView.ItemTemplate>
            <DataTemplate>
                <Image Source="{Binding .}"></Image>
            </DataTemplate>
        </cv:CarouselView.ItemTemplate>
    </cv:CarouselView >
</StackLayout>

C#

var image = new ObservableCollection<ImageSource>
{
    ImageSource.FromFile("Image1.jpg"),
    ImageSource.FromFile("Image2.jpg"),
    ImageSource.FromFile("Image3.jpg")
};

MainCarouselView.ItemsSource = image;

Device.StartTimer(TimeSpan.FromSeconds(2), (Func<bool>) (() =>
{
    MainCarouselView.Position = (MainCarouselView.Position + 1) % image.Count;
    return true;
}));

After running the app on the device or emulator I get this error:

Severity Code Description Project File Line Suppression State Error CS0433 The type 'CarouselView' exists in both 'Xamarin.Forms.CarouselView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'

I have tried to delete the Nuget Package and tried then the CarouselView remains empty and it also does not contain the property of Position . Any help will be appreciated.

EDIT: I have solved using CarouselView.FormsPlugin Xaml:

<controls:CarouselViewControl x:Name="MainCarouselView"  Grid.Row="0" Grid.ColumnSpan="3" Position="{Binding PositionIndex, Mode=TwoWay}">
                    <controls:CarouselViewControl.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding .}"></Image>
                        </DataTemplate>
                    </controls:CarouselViewControl.ItemTemplate>
              </controls:CarouselViewControl >

And kept the cs code same. Thanks for the help guys.

Use CarouselView control for Xamarin Forms https://github.com/alexrainman/CarouselView

and be sure you are following these steps:

In your iOS and Android projects call:

MainActivity.cs :

CarouselView.FormsPlugin.Android.CarouselViewRenderer.Init();

AppDelegate.cs :

CarouselView.FormsPlugin.iOS.CarouselViewRenderer.Init();

On your XAML view

xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"

You shoudn't use Xamarin.Forms.CarouselView plugin, as it's hasn't been updated for years...For those interested, it was supposed to be an optimised successor of the CarouselPage - you can read more about it from James' blog post . For some reason it has been completely abandoned by Xamarin.Forms team.

Xamarin.Forms.CarouselView 最后更新

Currently the best solution is to use Alex's Rainman CarouselView.FormsPlugin plugin, which is just great! However, I think currently it has some issues with supporting Xamarin.Forms 3.5 ( github issue )

NOTE : Depending on what exactly you want to achieve, you might want to have a look at the Sharpnado's HorizontalListView carousel layout, which I'm almost certain is based off of the Alex's package.

For the future, keep an eye on the CollectionView , which will be a base for the brand new CarouselView in the Xamarin.Forms 4.0. You can read a bit more about it (and see a preview) in this blog post

NOTE : Please avoid using CarouselPage as well as the Xamarin.Forms.CarouselView

The CarouselPage does not support UI virtualization. Therefore, performance may be affected if the CarouselPage contains too many child elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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