Bug 25754 - ListView uses scaledScreenSize.Height to define width
Summary: ListView uses scaledScreenSize.Height to define width
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC Windows
: Highest normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-01-06 16:10 UTC by Chen Lu
Modified: 2016-04-08 18:49 UTC (History)
7 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 Chen Lu 2015-01-06 16:10:43 UTC
In class Xamarin.Forms.ListView.cs (Xamarin.Forms.Core.dll portable version), there is a new override in 1.3.0,

protected override SizeRequest OnSizeRequest(Double widthConstraint, Double heightConstraint).

Should the line of code Double num = Math.Min(width, scaledScreenSize.Height) be Double num = Math.Min(width, scaledScreenSize.Width).

The scaledScreenSize.Height is used instead of scaledScreenSize.Width.

    protected override SizeRequest OnSizeRequest(Double widthConstraint, Double heightConstraint)
        Size size;
        Size size1 = new Size(40, 40);
        Double width = Device.Info.ScaledScreenSize.Width;
        Size scaledScreenSize = Device.Info.ScaledScreenSize;
        Double num = Math.Min(width, scaledScreenSize.Height);
        IList itemsSource = base.ItemsSource as IList;
        if (itemsSource == null || this.HasUnevenRows || this.RowHeight <= 0 || this.IsGroupingEnabled)
            Double width1 = Device.Info.ScaledScreenSize.Width;
            Size scaledScreenSize1 = Device.Info.ScaledScreenSize;
            size = new Size(num, Math.Max(width1, scaledScreenSize1.Height));
            size = new Size(num, (Double)(itemsSource.Count * this.RowHeight));
        return new SizeRequest(size, size1);
Comment 1 Udham Singh 2015-01-07 06:31:33 UTC
I have checked this issue and observed that when we implement the code given in bug description in an app, then we are getting option 'scaledScreenSize.Height' to define width along with option  'scaledScreenSize.Width' in auto completion window. 

Screencast : http://www.screencast.com/t/agjTvqyKSsj3

@Chen, Please let me know if I have to check something else to confirm this issue. Thanks!

Environmet Info :

Xamarin.Forms : 1.3.0

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.50938

Xamarin (a6d269d)
Comment 2 Chen Lu 2015-01-07 08:58:19 UTC
The code given in the bug description is not my code, it is from the code released by Xamarin Form 1.3.0.  Since I don't have the access to Device.Info, it is internal static, I cannot override this method as I want to use scaledScreenSize.Width.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-07 22:34:52 UTC
@Chen, if possible I think ideally the Xamarin QA team and the Xamarin.Forms team would love to get a simple complete Xamarin.Forms app that demonstrates a problem with the size of ListView as an attachment on this bug report. Perhaps nesting the sample ListView from [1] in some specific Page structure that imitates your full app would be sufficient?

> [1] https://github.com/xamarin/xamarin-forms-samples/blob/master/FormsGallery/FormsGallery/FormsGallery/ListViewDemoPage.cs

Thanks in advance for any sample app you might be able to provide!

I'm a member of the Support team rather than the Xamarin.Forms team, so at first glance, I'm not sure of the intention behind the use of `Math.Min(Device.Info.ScaledScreenSize.Width, Device.Info.ScaledScreenSize.Height)` as the width of the size request. In general I would not recommend guessing at the intention behind decompiled code. That said, switching the code as suggested in comment 0 would be equivalent to:
> Double num = Math.Min(Device.Info.ScaledScreenSize.Width, Device.Info.ScaledScreenSize.Width);

... which is in turn equivalent to:
> Double num = Device.Info.ScaledScreenSize.Width;

So I suspect there is an explanation for the use of `Math.Min()` to pick between the Width vs. the Height. Otherwise the developers would have just used `Device.Info.ScaledScreenSize.Width` directly. Still, the current code is puzzling. It sort of looks like the intention is that the ListView should always be oriented such that the horizontal axis is along the shorter axis of the display, but that is clearly not how the ListView works in practice.
Comment 5 Paul DiPietro [MSFT] 2016-04-08 18:49:11 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team