Forum Xamarin.Forms

How to add parent layout into XAML only for IOS

Liuk88Liuk88 ITMember ✭✭✭
edited January 2019 in Xamarin.Forms

Hello guys, I'm trying to add into a XAML file a parent layout.
I have a layout that I want to remain like this in Android
< StackLayout >
< /StackLayout >

while in IOS I would like to add another layout as parent:
< ScrollView >
< StackLayout >
< /StackLayout >
< /ScrollView >

I know that there is the OnPlatform property for the content view but I would like to not duplicate all the code of the layout 2 times since is a lot of code.
Is this possible? Or duplicate all the code with the OnPlatform is the only one solution?

Best Answer


  • GaetanFGaetanF USMember ✭✭✭

    Straight out of my head, try to create the StackLayout in the resource dictionary (or create a custom control) and use it alongside with the OnPlatform markup. Enclose the resource with the ScrollView on iOS

  • Liuk88Liuk88 ITMember ✭✭✭

    Thanks both for your answers, I used Colex suggestion cause really simple.

  • GaetanFGaetanF USMember ✭✭✭

    Great! It is not XAML as you asked though

  • petrKpetrK Member

    hey @GaetanF
    Can you expand on your xaml solution with an example?

    I have the following xaml

         <Grid RowSpacing="0" ColumnSpacing="0" x:Name="MainGrid">

    but on iOS I'd like it to look like

            <ScrollView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                    <Grid RowSpacing="0" ColumnSpacing="0" x:Name="MainGrid">
Sign In or Register to comment.