Bug 60690 - Putting View into ContentPage.Content in specific order breaks layout interaction (ONLY ON iOS!)
Summary: Putting View into ContentPage.Content in specific order breaks layout interac...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-15 12:38 UTC by dev.krzysiek
Modified: 2017-11-15 17:03 UTC (History)
3 users (show)

Tags: layout, ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 60690 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description dev.krzysiek 2017-11-15 12:38:08 UTC
This is the case i struggled with when wanted to set backgroundImage of page

Have this XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App1"
             x:Class="App1.MainPage">
    <Grid x:Name="ContentHolderGrid">
    <StackLayout >
        <Button Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
    </StackLayout>
    </Grid>
</ContentPage>

And this Code behind:

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            RelativeLayout layout = new RelativeLayout();
            


            Image backgroundImageHolder = new Image();
            backgroundImageHolder.Aspect = Aspect.Fill;
            layout.Children.Add(backgroundImageHolder,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height)
                );

            Grid grid = new Grid();
            grid.Children.Add(ContentHolderGrid);
            layout.Children.Add(grid,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height)
                );

            Content = layout;
        }
    }


On Android this code works fine. On iOS the touch (and probably all other interactions) on this layout is disabled (you can see it by the button not highlighting when tapped).

The solution to this is to put "Content = layout;" line to to the top so the resulting code looks like this:

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            RelativeLayout layout = new RelativeLayout();
            Content = layout;


            Image backgroundImageHolder = new Image();
            backgroundImageHolder.Aspect = Aspect.Fill;
            layout.Children.Add(backgroundImageHolder,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height)
                );

            Grid grid = new Grid();
            grid.Children.Add(ContentHolderGrid);
            layout.Children.Add(grid,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent((parent) => parent.Width),
                Constraint.RelativeToParent((parent) => parent.Height)
                );
        }
    }


After applying this change Android behaves the same way(correctly) and iOS also works correctly.

This is very strange and finding how to solve this bug was very time-consuming.