Forum Xamarin.Forms

Horizontal stacklayout with label bug on windows phone

MartinBoothMartinBooth USMember ✭✭

Good evening.

Using markup very similar to that in the xamarin forms tutorial I am unable to get the behaviour I want on windows phone.. I guess this is a bug because the iphone does behave as expected.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
  <StackLayout Orientation="Horizontal" VerticalOptions="Start">

    <Image Source="" WidthRequest="100" HeightRequest="100" />

    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
        <Label Text="Tthis is a test to see whether the text wraps correctly when it gets to the end on both IOS and Windows phone" />


On Windows Phone, the width of the label is greater than the remaining space available in the stacklayout, whereas on the iphone it wraps correctly. I have attached 2 screenshots to show this (take a look at where the text wraps on the windows phone image)


  • DanielLDanielL PLInsider ✭✭✭✭

    This occurs also on Android

  • MartinBoothMartinBooth USMember ✭✭

    A new label seems to have fixed it for me:

    public class Lbl : Label
        protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint)
            var sizeRequest = base.OnSizeRequest(widthConstraint, heightConstraint);
            return new SizeRequest(new Size(sizeRequest.Request.Width, sizeRequest.Request.Height), Size.Zero) ;
  • MartinBoothMartinBooth USMember ✭✭

    I spoke too soon.. This doesn't work either.. the label's height is too short if you do this.. I guess the height is whatever the height would have been if the label was the full width of the screen.

    If you stack these, they will overlap vertically

  • Taimoor.JanjuaTaimoor.Janjua DEMember ✭✭

    Did anyone of you find the solution on Windows Phone??

    In my case, I have a label that is horizontally centered and expanded.

    It goes of the screen, when the text is greater than one line.

    I solved it with width request, but with that its no more centered.

    Hope to hear soon!

    Kind Regards

    Taimoor Janjua

Sign In or Register to comment.