R.Extrant
R.Extrant

Reputation: 181

How to set a maximum height to Label Xamarin Forms?

I need your help !

In xamarin.forms, I would like a Label with a fixed Width. When the text is too long, it is on several lines. So, I would like set a maximum height or number of lines. I think to measure the string lengh but I no found method.

I hope there is a solution to Xamarin.Forms (PCL project). I don't want to do specific code for each platform if it's possible.

Thank you in advance !

Upvotes: 3

Views: 9202

Answers (3)

Mohammed Saquib
Mohammed Saquib

Reputation: 73

you can use "MaxLines" to display how many lines you want.

Upvotes: 2

Marko Rothstein
Marko Rothstein

Reputation: 441

I found a solution.

When I set HeightRequest property to Label, it didn't work. When I wrapped the Label in a StackLayout and set HeightRequest property to the StackLayout, I succeeded.

<StackLayout Orientation="Horizontal" HeightRequest="70">
    <Label Text="..." />
</StackLayout>

Upvotes: 5

AllDayer
AllDayer

Reputation: 993

There are a few options available. If you don't want the label to wrap you can set the Label.LineBreakMode to NoWrap. More info here.

You can directly specify a HeightRequest or set VerticalOptions on the Label.

Try posting a code example of what you have tried for more assistance.

Upvotes: 1

Related Questions