Bug 55183 - AbsoluteLayoutBounds & AbsoluteLayoutFlags with OnIdiom not working in ResourceDictionaries
Summary: AbsoluteLayoutBounds & AbsoluteLayoutFlags with OnIdiom not working in Resour...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-04-13 14:38 UTC by jared.fritsch
Modified: 2017-06-20 13:14 UTC (History)
4 users (show)

Tags: onidiom style staticresource ac
Is this bug a regression?: ---
Last known good build:


Attachments
Repro project (197.62 KB, application/x-zip-compressed)
2017-04-13 14:40 UTC, jared.fritsch
Details


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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description jared.fritsch 2017-04-13 14:38:29 UTC
### Overview
Controls are not visible when using an AbsoluteLayout.LayoutBounds ResourceDictionary object that contains idiom specific values. They do work however, when the AbsoluteLayout.LayoutBounds are set directory on the control. This same problem is occurring with AbsoluteLayout.LayoutFlags as well.

This works:

<AbsoluteLayout>
  <ContentView
    AbsoluteLayout.LayoutFlags="All">
    <AbsoluteLayout.LayoutBounds>
      <OnIdiom
        x:TypeArguments="Rectangle"
        Phone="0.5, 0.5, 1, 1"
        Tablet="0.5, 0.5, 0.8, 1" />
    </AbsoluteLayout.LayoutBounds>
    ...
  </ContentView>
</AbsoluteLayout>

This does not:

<Rectangle
  x:Key="AbsoluteLayoutBounds">
  <OnIdiom
    x:TypeArguments="Rectangle"
    Phone="0.5, 0.5, 1, 1"
    Tablet="0.5, 0.5, 0.8, 1" />
</Rectangle>

<AbsoluteLayout>
  <ContentView
    AbsoluteLayout.LayoutFlags="All"
    AbsoluteLayout.LayoutBounds="{StaticResource AbsoluteLayoutBounds}">
    ...
  </ContentView>
</AbsoluteLayout>

However, this does work:

<Rectangle
  x:Key="AbsoluteLayoutBounds">
  0.5, 0.5, 0.8, 1
</Rectangle>

<AbsoluteLayout>
  <ContentView
    AbsoluteLayout.LayoutFlags="All"
    AbsoluteLayout.LayoutBounds="{StaticResource AbsoluteLayoutBounds}">
    ...
  </ContentView>
</AbsoluteLayout>


### Steps to Reproduce
1. Open the attached repro project
2. Note the look of the first page
3. Click the "Go to non-working page" button to move to the second page
4. Note the look of the second page


### Expected Result
Controls using AbsoluteLayout.LayoutBounds that come from a resource dictionary should display the same way as controls that have AbsoluteLayout.LayoutBounds applied directly.


### Actual Result
Controls using AbsoluteLayout.LayoutBounds that come from a resource dictionary are not visible.


### Build Date & Hardware
April 12, 2017
iPad Air 1 - iOS 10.2.1
iPhone 6 Plus - iOS 10.1.1
Nexus 5 Simulator - Android 7.1
Nexus 9 Simulator - Android 7.1


### Additional Information
If OnIdiom is not used, it works just fine. My examples above highlight AbsoluteLayout.LayoutBounds not working but do note that AbsoluteLayout.LayoutFlags show the same incorrect behavior.
Comment 1 jared.fritsch 2017-04-13 14:40:07 UTC
Created attachment 21512 [details]
Repro project

Note that the Nuget packages were removed in order to get under the file size limit.
Comment 2 Jimmy [MSFT] 2017-04-17 23:05:27 UTC
I ran the attached project and I was able to reproduce the issue on both Android and iOS with Forms 2.3.4. I am confirming this report so the team can investigate further.

I also tried testing with 2.3.5-pre1 however this version caused an error to be thrown during runtime. The style from App.xaml shown below throws a XamlParse exception because it thinks the OnIdiom node is actually content but the Content of a Rectangle cannot be set because it has no Content property:

<Rectangle x:Key="GlobalInnerContainerAbsoluteLayoutBounds">
    <OnIdiom
        x:TypeArguments="Rectangle"
        Phone="0.5, 0.5, 1, 1"
        Tablet="0.5, 0.5, 0.8, 1" />
</Rectangle>

This error is also thrown during build if XamlC is enabled. However it does not occur in either case when using 2.3.4 so it is unclear whether it is related or not.
Comment 3 Rui Marinho 2017-06-19 17:57:36 UTC
this is now crashing on 2.3.5.239-pre3 even when loading the 1st page.
Comment 4 Stephane Delcroix 2017-06-19 20:10:27 UTC
@Jimmy: was it working on 2.3.4, or only not crashing ?

your analysis is correct, you can't assign a Rectangle from anything but a string.
Comment 5 Jimmy [MSFT] 2017-06-19 21:14:41 UTC
@Stephane It was not working with 2.3.4. It did not crash, but it failed silently and the children views were not visible. On 2.3.5 it now crashes at launch when it tries to parse the style in App.xaml.
Comment 6 Stephane Delcroix 2017-06-20 12:20:52 UTC
This

<Rectangle
  x:Key="AbsoluteLayoutBounds">
  <OnIdiom
    x:TypeArguments="Rectangle"
    Phone="0.5, 0.5, 1, 1"
    Tablet="0.5, 0.5, 0.8, 1" />
</Rectangle>

is an invalid syntax for declaring a Rectangle. It's unrelated to the OnIdiom. Rectangles can only be constructed from strings.

On the other the hand, this might work and do what you expect

<OnIdiom
    x:TypeArguments="Rectangle"
    x:Key="AbsoluteLayoutBounds"
    Phone="0.5, 0.5, 1, 1"
    Tablet="0.5, 0.5, 0.8, 1" />
Comment 7 jared.fritsch 2017-06-20 13:14:01 UTC
Thank you for the clarification, @Stephane! That is exactly the syntax I was looking for.