Share via

Load ContentPage into CarouselPage

Anonymous
2022-04-24T21:16:27.487+00:00

Hi,

In below example I have multiple ContentPages inside my CarouselPage but this will make the file too long and difficult to maintain,

Can I create a separate ContentPage file for each of them and then load it into my CarouselPage?

How can I do that please?

 <?xml version="1.0" encoding="utf-8" ?>
 <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
     ios:Page.UseSafeArea="True" 
     CurrentPageChanged="CarouselPage_CurrentPageChanged"
     x:Class="Kalko.MainPage">
     <NavigationPage.TitleView>
         <StackLayout>
         <Label Text="Home Page" VerticalOptions="Center" />
         <Image HorizontalOptions="End" VerticalOptions="Center">
         <Image.Source>
             <FontImageSource FontFamily="FontSolid" Size="30" Glyph="{StaticResource IconFavorite}" />
         </Image.Source>
         </Image>
         </StackLayout>
     </NavigationPage.TitleView>
     <ContentPage x:Name="ContentPageHomePage">
     </ContentPage>
     <ContentPage x:Name="ContentPagePag2">
     </ContentPage>
     <ContentPage x:Name="ContentPagePag3">
     </ContentPage>
     <ContentPage x:Name="ContentPagePag4">
     </ContentPage>
 </CarouselPage>
Developer technologies | .NET | Xamarin

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
    2022-04-25T05:32:26.413+00:00

    Hello,

    You can refer to CarouselPage Class to find the solution in Remarks.

    If you want to load ContentPages into your CarouselPage, you could use the Children property to set your pages.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.