Bug 27647 - WidthRequest is only used when a HorizontalOption is explicitly set
Summary: WidthRequest is only used when a HorizontalOption is explicitly set
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.5
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-03-04 11:05 UTC by John Miller [MSFT]
Modified: 2015-03-07 06:33 UTC (History)
5 users (show)

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 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:

Description John Miller [MSFT] 2015-03-04 11:05:23 UTC

   WidthRequest does not seem to be used unless the HortizontalOption is set to Start or End or Center.

**Steps to Reproduce:**

   MainPage = new ContentPage
                Content = new StackLayout
                    VerticalOptions = LayoutOptions.Center,
                    Children =
                        new Label { Text="Hi", WidthRequest = 100, HeightRequest = 100, BackgroundColor = Color.Red }

**Actual Results:**

   The Label expands the entire width of the screen: http://screencast.com/t/7DHnLZf8Tn

**Expected Results:**

   The Label should only be 100 units wide. 

**Build Date & Platform:**

   XF 1.3.5

**Additional Information:**

   Add a HorizontalOption = LayoutOption.Start to the Label and the Expected Results will be seen.
Comment 1 narayanp 2015-03-05 03:15:03 UTC
I have tried to reproduce this issue using steps mentioned in bug description and able to reproduce. WidthRequest is not used if  HorizontalOption is not explicitly set. If we added this line of code "HorizontalOptions = LayoutOptions.Start" then WidthRequest is works and shows expected result.

Here is the screencast for the same: http://www.screencast.com/t/niiM6D0M
IDE Log: https://gist.github.com/sunil360/bcaeb9278651ed711379

Hence confirming this issue.

Environment info:

=== Xamarin Studio ===

Version 5.7.2 (build 8)
Installation UUID: 561c7a69-0a91-4bae-ad7c-f0c79d594337
	Mono 3.12.0 ((detached/b8f5055)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000077

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 9dd40fb
Build date: 2015-03-04 15:57:52-0500

=== Xamarin.Android ===

Version: (Trial Edition)
Android SDK: /Users/tajinder/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507020008
Git revision: 64a4266f0a82f7558472383d8ae66a526b3b881d
Build date: 2015-02-25 11:22:12-05
Xamarin addins: 1cb443ca2dddd9933d748e035560f06cf9c246bd

=== Operating System ===

Mac OS X 10.8.4
Darwin Tajinders-iMac.local 12.4.2 Darwin Kernel Version 12.4.2
    Mon Jun 17 18:00:12 PDT 2013
    root:xnu-2050.45.8~1/RELEASE_X86_64 x86_64
Comment 2 Jason Smith [MSFT] 2015-03-07 06:24:16 UTC
This is a misunderstanding of how a StackLayout works.

The default behavior of a Label is to Fill (Horizontal/Vertical options are set to Fill). In a vertical stacklayout, the stack layout allocates a space to each of its children equal to the CHILDS height request and the STACKLAYOUT width. In other words the child always gets the off-axis size of the Stack.

When the childs horizontaloptions are set to Fill this means the child will then accept all this space, even though it may not need all of it. Which is what is happening here.
Comment 3 Andrei.N 2015-03-07 06:28:51 UTC
Does this mean WidthRequest has less priority than HorizontalOptions?

By default, WidthRequest is -1. If I set WidthRequest to a specific value, this is a clear indication that it must have a specific width, I do not want it to fill the space (default behavior).
Comment 4 Andrei.N 2015-03-07 06:33:07 UTC
In other word, every time I want it to have a specific width, I also must set HorizontalOptions as well (to something like Star, End, Center), otherwise it's ignored.

Wouldn't be good for the layout engine to just layout the view centered?
This is how it works for example on Windows.