Tompi
Tompi

Reputation: 296

Xamarin.Forms 3.6 breaking carouselview?

Xamarin.Forms 3.6 has included the CarouselView, so I cant use the nuget package anymore, but shipped version seems to be lacking some features, more specifically indicators seems to be missing entirely?

Here is my old code, which does not compile anymore:

            // Create the carousel
            _carouselView = new CarouselView()
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            _carouselView.ItemTemplate = template;
            _carouselView.SetBinding(ItemsView.ItemsSourceProperty, nameof(_viewModel.CarouselItems));
            _carouselView.SetBinding(CarouselView.PositionProperty, nameof(_viewModel.Position));

            // Create page-indicator
            var indicator = new CarouselIndicators { ItemsSource = _viewModel.CarouselItems };
            indicator.Margin = new Thickness(20, 20, 20, 0);
            indicator.SetBinding(CarouselIndicators.PositionProperty, nameof(_viewModel.Position));

CarouselView.Position and CarouselIndicators are not there in 3.6 :( Do I need to implement indicators manually in 3.6?

Upvotes: 0

Views: 689

Answers (1)

As Xamarin.Forms 3.6 includes an implementation of CarouselView, if you upgrade from using Xamarin.Forms<3.6 and Xamarin.Forms.CarouselView to Xamarin.Forms 3.6 it is going to break. Because

  1. the Xamarin.Forms.CarouselView nuget package is deprecated and hasn't been updated for 2 years
  2. by having Xamarin.Forms 3.6 and Xamarin.Forms.CarouselView in parallel you will have a naming conflict between the 2 CarouselView elements
  3. the Xamarin.Forms.CarouselView implementation in Xamarin.Forms 3.6 doesn't contain a Position property

A lot of projects switched to a community implementation of CarouselViews :

Solution for you would be :

  1. Remove Xamarin.Forms.CarouselView
  2. Add https://github.com/AndreiMisiukevich/CardView (CardsView nuget package)
  3. Upgrade Xamarin.Forms to 3.6
  4. Change
_carouselView.SetBinding(CarouselView.PositionProperty, nameof(_viewModel.Position));

to

_carouselView.SetBinding(CardsView.SelectedIndexProperty, nameof(_viewModel.Position));

Upvotes: 4

Related Questions