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; }
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.
Answers
And I have observed that position never have the value of zero
@BadamSujithKumar
Do you bind other value to
Position
property?@BadamSujithKumar
I think, you should try this plugin https://github.com/AndreiMisiukevich/CardView
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.
@BillyLiu Yes I have bind the other value
@BadamSujithKumar
You have to update CarouselView Position inside MainThread.
eg: protected override void OnAppearing()
{
base.OnAppearing();
@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