syaaa
syaaa

Reputation: 31

How to set a max length for label text in Xamarin

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

Upvotes: 3

Views: 5813

Answers (3)

bhavya joshi
bhavya joshi

Reputation: 1136

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"/>

Upvotes: 5

Volodymyr Romaniuk
Volodymyr Romaniuk

Reputation: 21

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

Upvotes: 1

Grady
Grady

Reputation: 174

Have you looked at LineBreakMode? https://developer.xamarin.com/api/type/Xamarin.Forms.LineBreakMode/ This is what I used to actually make my labels longer.

Upvotes: 2

Related Questions