Bug 38564 - ConstraintExpression in Style does not work
Summary: ConstraintExpression in Style does not work
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-09 08:09 UTC by Michael Rumpler
Modified: 2016-12-22 04:34 UTC (History)
5 users (show)

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


Attachments
repro project (148.64 KB, application/x-zip-compressed)
2016-02-09 08:09 UTC, Michael Rumpler
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 for Bug 38564 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 Michael Rumpler 2016-02-09 08:09:26 UTC
Created attachment 14954 [details]
repro project

I tried moving my RelativeLayout.* properties to a Style, but they do not work. My xaml looks like this:

	<ContentPage.Resources>
		<ResourceDictionary>
			<Style x:Key="MiddleLabel" TargetType="Label">
				<Setter Property="Text" Value="This Label should be displayed in the middle and take half of the screen." />
				<Setter Property="BackgroundColor" Value="Red" />
				<Setter Property="RelativeLayout.XConstraint" Value="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.25}" />
				<Setter Property="RelativeLayout.YConstraint" Value="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.25}" />
				<Setter Property="RelativeLayout.WidthConstraint" Value="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5}" />
				<Setter Property="RelativeLayout.HeightConstraint" Value="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}" />
			</Style>

		</ResourceDictionary>
	</ContentPage.Resources>

	<RelativeLayout>
		<Label Style="{DynamicResource MiddleLabel}" />
	</RelativeLayout>

The Text and BackgroundColor from the Style are applied, but the attached properties for RelativeLayout are not. The Label is displayed at the top left corner and has the size of the text.

The desired result would be, that the ConstraintExpression is parsed when the Style is parsed, but it should only be evaluated during layouting phase. It must not search for the parent too early.
 
I already had a short discussion with Stephane Delcroix on this in https://forums.xamarin.com/discussion/comment/179494#Comment_179494

I tested with XF 2.1.0 pre3 and pre4 on iOS only. But I guess, this bug affects all platforms.