CarouselView.FormsPlugin in shell

HamittirpanHamittirpan Member ✭✭✭
edited October 9 in Xamarin.Forms

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
    }
}
Tagged:

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think there is a new CarouselView in XF 4.2 (or 4.3)...

  • HamittirpanHamittirpan Member ✭✭✭

    So, what should I do?

  • LandLuLandLu Member, Xamarin Team Xamurai

    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.

  • HamittirpanHamittirpan Member ✭✭✭

    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?

  • HamittirpanHamittirpan Member ✭✭✭

    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?

            protected override void OnCreate(Bundle savedInstanceState)
            {
                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;
                base.OnCreate(savedInstanceState);
    
                Xamarin.FormsMaps.Init(this, savedInstanceState);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);
                Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
    
                RequestPermissions(Permission, RequestId);
    
                global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
                ZXing.Net.Mobile.Forms.Android.Platform.Init();
            initControls();
    
                LoadApplication(new App());
            }
    
  • HamittirpanHamittirpan Member ✭✭✭
    edited October 10

    Sorunumu CardsView eklentisi kullanarak çözdüm.

Sign In or Register to comment.