Bug 44774 - Entry Field does not resize when setting FontSize
Summary: Entry Field does not resize when setting FontSize
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2016-09-27 10:03 UTC by Paul Diston
Modified: 2017-06-21 01:04 UTC (History)
7 users (show)

Tags: ac
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:
Status:
RESOLVED FIXED

Description Paul Diston 2016-09-27 10:03:10 UTC
In my Xamarin Forms app running on iOS, when I set the FontSize of an Entry to say 42, the Entries do not resize so for example the tail of a lower case g is cut off and the top and bottom of an upper case G are also cut off.

I have tried the following code in a custom renderer however this has had little effect :-

public class MyEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                ResizeHeightWithText(Control);
            }
        }
        void ResizeHeightWithText(UITextField textField, float maxHeight = 960f)
        {
            var width = textField.Frame.Width;
            var size = ((NSString)textField.Text).StringSize(textField.Font, new CGSize(width, maxHeight),
                    UILineBreakMode.WordWrap);
            var labelFrame = textField.Frame;
            labelFrame.Size = new CGSize(width, size.Height);
            textField.Frame = labelFrame;
        }
    }
Is there a solution to this problem?
Comment 1 Samantha Houts [MSFT] 2016-10-04 00:20:11 UTC
I have reproduced this by putting an Entry control in a StackLayout. The StackLayout appears to be constraining the height of the Entry. 

You can work around the issue by setting the VerticalOptions of the Entry control to FillAndExpand.
Comment 2 Paul Diston 2016-10-04 14:55:48 UTC
My Entry controls are set to have VerticalOptions of FillAndExpand however this does not allow them to resize correctly, inline with the original bug.
Comment 3 Samantha Houts [MSFT] 2016-10-04 16:38:03 UTC
Are you able to provide a more complete sample to help us ensure that we're reproducing the same behavior?
Comment 4 Jim Bennett 2016-11-16 03:03:02 UTC
I can reproduce this easily - don't even need a stack layout.

Create a brand new Xamarin Forms app in Xamarin Studio, change the label to an entry with a font size of 64:

<Entry Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Fill" FontSize="64" />

Run this on Android/iOS and you'll see the text doesn't fit.
Comment 5 Jim Bennett 2016-11-16 03:05:44 UTC
I've tested this with the latest stable and the latest pre-release version. Happens on both.
Comment 6 Jim Bennett 2016-11-16 03:44:03 UTC
As a workaround I've found if you explicitly call ForceLayout after the page is loaded (e.g in OnAppearing) the entry control is sized correctly
Comment 7 Jim Bennett 2016-11-23 21:27:10 UTC
Update - calling force layout only works in the simulator, not on an actual device
Comment 8 Stephane Delcroix 2017-06-12 13:57:43 UTC
see https://github.com/xamarin/Xamarin.Forms/pull/987
Comment 9 John Hardman 2017-06-19 12:13:02 UTC
Also a problem on UWP. Shall I raise a new bug for UWP?
Comment 10 Rui Marinho 2017-06-21 01:04:19 UTC
John please do.. this one should be fixed on 2.3.6-pre1