Hi everyone !
I use the CarouselView.FormsPlugin in my project. I also use shell structure in my project.
When my application opens, the CarouselViewFormsPlugin actually works as I want. However, when I go to another page and return to this page, the carousel does not appear. Please help me ! How can ı solved ?
My code;
<?xml version="1.0" encoding="UTF-8"?>
<Shell.TitleView> <AbsoluteLayout Padding="0,0,50,0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <Image Source="DL.png" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" /> </AbsoluteLayout> </Shell.TitleView> <ContentPage.Resources> <local:ImageConverter x:Key="ImageConverter" /> </ContentPage.Resources> <Grid> <Grid.RowDefinitions> <!--<RowDefinition Height="*"/> <RowDefinition Height="0.5"/> <RowDefinition Height="Auto"/>--> <RowDefinition Height="8*"/> <RowDefinition Height="0.5"/> <RowDefinition Height="2*"/> </Grid.RowDefinitions> <ContentView Grid.Row="0"> <controls:CarouselViewControl ItemsSource="{Binding}" ShowArrows="False" ShowIndicators="True" IndicatorsTintColor="Gray" CurrentPageIndicatorTintColor="#ED6933"> <controls:CarouselViewControl.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ContentView Grid.Row="0" Padding="0,5,0,5"> <Image Source="{Binding CampaignPicture, Converter={StaticResource ImageConverter}}" Aspect="AspectFit"> </Image> </ContentView> <ContentView Grid.Row="1" Padding="5,5,5,5"> <Label Text="{Binding CampaignName}" TextColor="#ED6933" FontSize="25" HorizontalTextAlignment="Center"/> </ContentView> <ContentView Grid.Row="2" Padding="10,5,10,5"> <Label Text="{Binding CampaignName2}" TextColor="White" FontSize="13" HorizontalTextAlignment="Center"/> </ContentView> <ContentView Grid.Row="3" Padding="10,0,10,10"> <Label Text="{Binding CampaignDetail}" TextColor="White" FontSize="13" HorizontalTextAlignment="Center"/> </ContentView> <ContentView Grid.Row="4" Padding="20,10,20,5"> <Label Text="{Binding EndDateTimeShort}" TextColor="#ED6933" FontAttributes="Bold" FontSize="15" HorizontalOptions="End" HorizontalTextAlignment="Center"/> </ContentView> </Grid> </DataTemplate> </controls:CarouselViewControl.ItemTemplate> </controls:CarouselViewControl> </ContentView> <BoxView Grid.Row="1" BackgroundColor="Gray"/> <StackLayout Grid.Row="2" Padding="45,5,45,5" Spacing="5"> <Label Text="Kampanyalardan Yararlanmak için barkodunuzu oluşturun" HorizontalTextAlignment="Center" HorizontalOptions="Center" VerticalOptions="Center" TextColor="White"/> <Button Text="Barkod Oluştur" BackgroundColor="#ED6933" TextColor="White" BorderColor="Black" BorderWidth="1"/> </StackLayout> </Grid>
.cs
namespace GulaylarMenuDesign.Views { public partial class CarouselCampaings : ContentPage { readonly ServiceManager manager = new ServiceManager(); readonly IList<AppCampaign> model = new ObservableCollection<AppCampaign>(); AppCustomer customerModel = new AppCustomer(); public CarouselCampaings() { LoadData(); BindingContext = model; InitializeComponent(); NavigationPage.SetTitleIconImageSource(this, "DL.png"); } protected async override void OnAppearing() { base.OnAppearing(); customerModel = await manager.GetCustomerUpdatedInfo(Helpers.Settings.GeneralSettingsPass); CrossSettings.Current.AddOrUpdateValue("Information", JsonConvert.SerializeObject(customerModel)); } #region Get Campaing Data From Api private async void LoadData() { this.IsBusy = true; try { foreach (AppCampaign item in await manager.GetAll()) model.Add(item); } finally { this.IsBusy = false; } } #endregion } }
I've tried this plugin on my side and this issue occurs. However, after some searching, I found this was a known issue:
https://github.com/alexrainman/CarouselView/issues/509
If you do want to consume this control try the prior version 5.0.2. It won't be disappeared after navigation.
Moreover, if you want to consume the latest version you have to initialize the control in the OnAppearing
event:
CarouselView.FormsPlugin.Abstractions.CarouselViewControl MyCarouselView; protected override void OnAppearing() { base.OnAppearing(); if (MyCarouselView != null) { ParentLayout.Children.Remove(MyCarouselView); MyCarouselView = null; } MyCarouselView = new CarouselView.FormsPlugin.Abstractions.CarouselViewControl(); MyCarouselView.SetBinding(CarouselView.FormsPlugin.Abstractions.CarouselViewControl.ItemsSourceProperty, "myItemsSource"); MyCarouselView.ItemTemplate = Resources["CarouselViewTemplate"] as DataTemplate; ParentLayout.Children.Add(MyCarouselView, 0, 0); }
But I don't think this is a good approach.
Answers
I think there is a new CarouselView in XF 4.2 (or 4.3)...
So, what should I do?
There's a Carousel View in Xamarin Forms too:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/
You can try to use it in Shell to see whether it works or not. Follow this blog to build it:
https://devblogs.microsoft.com/xamarin/carouselview-xamarin-forms-4-3-prerelease/
However, it is still in preview. But if you are trying a third party plugin it's hard to say what causes the issue.
Hi @LeonLu
I have doubts to use because it is 4.3 --> prerelase.
I tried to use normal carouselview like the first link, but it doesn't have an indicator. Is there a way to add it?

Hi @LeonLu @AlessandroCaliaro
I'm including my plugin in my MainActivity class. ( initControls(); ). Does my app appear and disappear once because it only loads once?
Sorunumu CardsView eklentisi kullanarak çözdüm.
I've tried this plugin on my side and this issue occurs. However, after some searching, I found this was a known issue:
https://github.com/alexrainman/CarouselView/issues/509
If you do want to consume this control try the prior version 5.0.2. It won't be disappeared after navigation.
Moreover, if you want to consume the latest version you have to initialize the control in the
OnAppearing
event:But I don't think this is a good approach.