How to set a max length for label text in Xamarin

Viewed 4478

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

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

Thank you

3 Answers

MaxLines property is your answer. It's bindable too.

And if you want two show three dots after certain lines for overflowing text , use LineBreakMode="TailTruncation"

Example:

<Label Text="{Binding LargeText}"  MaxLines="2" LineBreakMode="TailTruncation"/>

In Xamarin.Forms 3.4 you can use Label's "MaxLines" property to set maximum lines. Also, it's a bindable property

Related