Bug 43716 - Height = GridLength.Auto in RowDefinition does not handle content of word-wrapped Label on UWP and WinRT
Summary: Height = GridLength.Auto in RowDefinition does not handle content of word-wra...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-08-24 18:48 UTC by John Hardman
Modified: 2017-03-21 18:29 UTC (History)
6 users (show)

Tags: Grid GridLength.Auto Height Label WordWrap
Is this bug a regression?: ---
Last known good build:


Attachments
Repro Project (281.70 KB, application/x-zip-compressed)
2017-01-09 19:20 UTC, E.Z. Hart [MSFT]
Details
Screenshot showing problem using 2.3.3.180 (101.26 KB, image/png)
2017-01-12 17:07 UTC, John Hardman
Details
updated repro project (289.30 KB, application/x-zip-compressed)
2017-03-21 18:29 UTC, Jimmy [MSFT]
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 FIXED

Description John Hardman 2016-08-24 18:48:47 UTC
On UWP and WinRT, with a ViewCell containing a Grid, with RowDefinition using Height = GridLength.Auto , and with that row containing a Label that word-wraps, the height of the row does not expand to contain the label. Instead, the label is cropped, resulting in information not being displayed that should be.

I have copied the source of the module where this shows up below.

The key bits are:
                    MyAppLabel label = new MyAppLabel
                    {
                        // other stuff here
                        LineBreakMode = LineBreakMode.WordWrap,  // Grid does not cope with this
                        VerticalOptions = LayoutOptions.CenterAndExpand,
                        // other stuff here
                    };

                    switchPanelGrid.RowDefinitions.Add(
                        new RowDefinition
                        {
                            Height = GridLength.Auto // This does not automatically re-size to contain a word-wrapped Label
                        });

                    switchPanelGrid.Children.Add(
                        label, 1, 2, 0, 1);

And label is populated with a string that word-wraps (I do this using binding).



using System;

using Xamarin.Forms;

using CommonInfrastructure;
using MyApp_ViewModels;

namespace ViewsUsingXamarinForms
{
    public class MyAppSwitchTemplatedView : DataTemplate
    {
        public MyAppSwitchTemplatedView(
            IMyAppViewState MyAppViewState) :
            base(() =>
            {
                try
                {
                    MyAppLabel label = new MyAppLabel
                    {
                        ClassId = "MyApp_ClassId_Label",
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        HorizontalTextAlignment = TextAlignment.Start,
                        InputTransparent = true,
                        LineBreakMode = LineBreakMode.WordWrap,  // Grid does not cope with this
                        Margin = new Thickness(0, 0, 10, 0),
                        VerticalOptions = LayoutOptions.CenterAndExpand,
                        VerticalTextAlignment = TextAlignment.Center,
                    };

                    label.SetBinding(MyAppLabel.AutomationIdProperty,
                        new Binding(
                            nameof(MyAppSwitchViewModel.AutomationId),
                            BindingMode.OneWay,
                            MyAppAppendTextConverter.Instance,
                            "_Label",
                            null));

                    label.SetBinding(VisualElement.BackgroundColorProperty,
                        nameof(MyAppSwitchViewModel.BackgroundColor),
                        BindingMode.OneWay);

                    label.SetBinding(Label.FontAttributesProperty,
                        nameof(MyAppSwitchViewModel.FontAttributes),
                        BindingMode.OneWay);

                    label.SetBinding(Label.FontFamilyProperty,
                        nameof(MyAppSwitchViewModel.FontFamily),
                        BindingMode.OneWay);

                    label.SetBinding(Label.FontSizeProperty,
                        nameof(MyAppSwitchViewModel.FontSize),
                        BindingMode.OneWay);

                    label.SetBinding(MyAppSwitch.IsEnabledProperty,
                        nameof(MyAppSwitchViewModel.IsEnabled),
                        BindingMode.OneWay);

                    label.SetBinding(Label.TextProperty,
                        nameof(MyAppSwitchViewModel.Text),
                        BindingMode.OneWay,
                        MyAppTextToUpperCaseConverter.Instance);

                    label.SetBinding(Label.TextColorProperty,
                        nameof(MyAppSwitchViewModel.EnabledOrDisabledTextColor),
                        BindingMode.OneWay);

                    MyAppSwitch xswitch = new MyAppSwitch
                    {
                        HorizontalOptions = LayoutOptions.End,
                        InputTransparent = false,
                        VerticalOptions = LayoutOptions.Center,
                        //IsToggled = true,
                        Margin = 0,
                    };

                    xswitch.SetBinding(MyAppLabel.AutomationIdProperty,
                        new Binding(
                            nameof(MyAppSwitchViewModel.AutomationId),
                            BindingMode.OneWay,
                            MyAppAppendTextConverter.Instance,
                            "_Switch",
                            null));

                    xswitch.SetBinding(VisualElement.BackgroundColorProperty,
                        nameof(MyAppSwitchViewModel.BackgroundColor),
                        BindingMode.OneWay);

                    xswitch.SetBinding(MyAppSwitch.IsEnabledProperty,
                        nameof(MyAppSwitchViewModel.IsEnabled),
                        BindingMode.OneWay);

                    xswitch.SetBinding(
                        MyAppSwitch.IsToggledProperty,
                        new Binding(
                            nameof(MyAppSwitchViewModel.IsOn),
                            BindingMode.TwoWay));

                    Grid switchPanelGrid = new Grid
                    {
                        ClassId = "MyApp_ClassId_Grid",
                        ColumnDefinitions = new ColumnDefinitionCollection(),
                        ColumnSpacing = 0,
                        HorizontalOptions = LayoutOptions.Fill,
                        IsVisible = true,
                        Padding = new Thickness(10, 10, 10, 10),
                        RowDefinitions = new RowDefinitionCollection(),
                        RowSpacing = 0,
                        VerticalOptions = LayoutOptions.Start
                    };

                    switchPanelGrid.SetBinding(MyAppLabel.AutomationIdProperty,
                        new Binding(
                            nameof(MyAppSwitchViewModel.AutomationId),
                            BindingMode.OneWay,
                            MyAppAppendTextConverter.Instance,
                            "_Grid",
                            null));

                    switchPanelGrid.SetBinding(VisualElement.BackgroundColorProperty,
                        nameof(MyAppSwitchViewModel.BackgroundColor),
                        BindingMode.OneWay);

                    switchPanelGrid.ColumnDefinitions.Add(
                        new ColumnDefinition
                        {
                            Width = new GridLength(1, GridUnitType.Star)
                        });
                    switchPanelGrid.ColumnDefinitions.Add(
                        new ColumnDefinition
                        {
                            Width = new GridLength(23, GridUnitType.Star)
                        });
                    switchPanelGrid.ColumnDefinitions.Add(
                        new ColumnDefinition
                        {
                            Width = new GridLength(1, GridUnitType.Auto)
                        });
                    switchPanelGrid.ColumnDefinitions.Add(
                        new ColumnDefinition
                        {
                            Width = new GridLength(1, GridUnitType.Star)
                        });

                    switchPanelGrid.RowDefinitions.Add(
                        new RowDefinition
                        {
                            Height = GridLength.Auto // This does not automatically re-size to contain a word-wrapped Label
                        });
                    switchPanelGrid.RowDefinitions.Add(
                        new RowDefinition
                        {
                            Height = GridLength.Auto
                        });

                    switchPanelGrid.Children.Add(
                        label, 1, 2, 0, 1);
                    switchPanelGrid.Children.Add(xswitch, 2, 3, 0, 1);
                    switchPanelGrid.Children.Add(
                        MyAppTemplateHelpers.CreateSeparator(false),
                        0, 4, 1, 2);

                    ViewCell vc = new ViewCell
                    {
                        View = switchPanelGrid
                    };

                    return vc;

                }
                catch (Exception ex)
                {
                    InsightsWrapper.SilentlyReportException(ex);
                    return new ViewCell
                    {
                        View = new Label
                        {
                            Text = String.Format("Exception {0}", ex.ToString())
                        }
                    };
                }
            })
        {
            // no-op
        }

    } // public class MyAppSwitchTemplatedView : DataTemplate

} // namespace ViewsUsingXamarinForms

// eof
Comment 1 georg.haberl 2016-11-18 08:07:51 UTC
duplicate of Bug 42559 ?
Comment 2 E.Z. Hart [MSFT] 2017-01-09 19:20:30 UTC
Created attachment 19138 [details]
Repro Project
Comment 3 E.Z. Hart [MSFT] 2017-01-09 19:21:57 UTC
John,

With the attached repro project and XF version 2.3.3.175, this seems to be working correctly. Are you still seeing the issue with the latest version of XF?
Comment 4 John Hardman 2017-01-09 23:20:26 UTC
@E.Z. Hart - I haven't upgraded to 2.3.3.175 yet. I am still seeing the problem on 2.3.2.127
Comment 5 John Hardman 2017-01-10 18:56:11 UTC
@E.Z. Hart - Just upgraded to 2.3.3.180 . The problem still occurs, but not on every line that has wrapping. Guessing there's an edge case not being handled.
Comment 6 E.Z. Hart [MSFT] 2017-01-12 16:29:50 UTC
(In reply to John Hardman from comment #5)
> @E.Z. Hart - Just upgraded to 2.3.3.180 . The problem still occurs, but not
> on every line that has wrapping. Guessing there's an edge case not being
> handled.

Do you mean that you're seeing the problem in the attached repro project, or in your own project?

If it's in your own project, could you provide a screenshot or a small repro project demonstrating the issue?
Comment 7 John Hardman 2017-01-12 17:06:43 UTC
@E.Z. Hart - In my own project. Please see screenshot.
Comment 8 John Hardman 2017-01-12 17:07:26 UTC
Created attachment 19308 [details]
Screenshot showing problem using 2.3.3.180
Comment 9 John Hardman 2017-03-21 11:24:56 UTC
Changed status back to NEW as requested screenshot was supplied a couple of months ago
Comment 10 Jimmy [MSFT] 2017-03-21 18:29:17 UTC
Created attachment 20532 [details]
updated repro project

I was able to modify the existing project so it reproduces the issue described and I've attached the new version.

With Forms 2.3.3.180 and 2.3.4-pre5 the row height did not fill the Label so some of the text appears to be cropped as in the screenshot in comment 8.

However with the latest 2.3.5 nightly build the issue appears to be fixed (possibly with this PR[1]) and the entire Label text is visible within the row.


### Version Tests
2.3.5.72-nightly    GOOD
2.3.4-pre5          BAD
2.3.3.193           BAD

[1] https://github.com/xamarin/Xamarin.Forms/pull/639