locked
I am unable to set the particular page in Carousel view RRS feed

  • Question

  • User293836 posted

    Hi, I am implemented the Carousel view using https://blog.xamarin.com/flip-through-items-with-xamarin-forms-carouselview/. And I am able to implement the Carousel, *But My Problem I want to set the startup page while opening (I mean when page is loaded the carousel view should show 5th page or 4th index) *

    Plugin Used Xamarin.Forms.CarouselView (2.3.0-pre2)

    What I tried Case 1: I have used Data binding in xaml but it always showing first page or index of zero

    Case 2: I have used Data binding from .cs file like CarouselView.ItemSource= Images; and CarouselView.Position=5; but is giving unhandled exception i.e, System.DivideByZeroException: Attempted to divide by zero.

    Here is the Sample code

    Case 1:

                <cv:CarouselView Position="{Binding Position, Mode=TwoWay}" ItemSelected="CarouselAlbumItems_ItemSelected" ItemsSource="{Binding AlbumItems}" x:Name="CarouselAlbumItems">
                    <cv:CarouselView.ItemTemplate>
                        <DataTemplate>
                            <Grid  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Image x:Name="imgAlbumItemName" Grid.RowSpan="2" Aspect="AspectFit" IsVisible="{Binding IsImage}" >
                                    <Image.Source>
                                        <UriImageSource Uri="{Binding AlbumItemPath}" CacheValidity="14" />
                                    </Image.Source>
                                </Image>
                            </Grid>
                        </DataTemplate>
                    </cv:CarouselView.ItemTemplate>
                </cv:CarouselView>
    

    Case 2:

        protected  override void OnAppearing()
        {
            base.OnAppearing();
            CarouselAlbumItems.ItemsSource = selectedItem.AlbumItems;
            CarouselAlbumItems.Position = position;            
        }
    
    Thursday, July 26, 2018 6:51 PM

Answers

  • User21936 posted

    Xamarin.Forms.CarouselView is an old library that has not been updated in 2 years and never made it out of pre-release, not something I would recommend for production use. I would recommend other options, like AndreiMisiukevich_'s suggestion.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 10, 2018 1:29 AM

All replies

  • User293836 posted

    And I have observed that position never have the value of zero

    Thursday, July 26, 2018 6:53 PM
  • User364855 posted

    @BadamSujithKumar

    <cv:CarouselView Position="{Binding Position, Mode=TwoWay}" ItemSelected="CarouselAlbumItems_ItemSelected" ItemsSource="{Binding AlbumItems}" x:Name="CarouselAlbumItems">
    

    Do you bind other value to Position property?

    Monday, July 30, 2018 9:57 AM
  • User198446 posted

    @BadamSujithKumar I think, you should try this plugin https://github.com/AndreiMisiukevich/CardView

    Monday, July 30, 2018 11:49 AM
  • User21936 posted

    Xamarin.Forms.CarouselView is an old library that has not been updated in 2 years and never made it out of pre-release, not something I would recommend for production use. I would recommend other options, like AndreiMisiukevich_'s suggestion.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 10, 2018 1:29 AM
  • User293836 posted

    @BillyLiu Yes I have bind the other value

    Friday, August 10, 2018 6:23 AM
  • User380258 posted

    @BadamSujithKumar

    You have to update CarouselView Position inside MainThread.

    eg: protected override void OnAppearing() { base.OnAppearing();

            // Iphone working but in Android not working "Devide by Zero Exception"
            //CarouselMain.Position = pos;
    
            Device.BeginInvokeOnMainThread(() => {
    
                CarouselMain.Position = pos;
            });
    
        }
    
    Wednesday, January 30, 2019 11:56 AM
  • User293836 posted

    @Alamgeer_Ashraf

    Thanks for the reply, I did not check your answer because I had been resolved the problem before your comment. I am able to solved by using latest nuget as suggested by @JGoldberger

    Thursday, January 31, 2019 4:14 AM