Hot off the press, another PR just got merged into the Xamarin.Forms repository. This time, adding a new feature on a Label, the ability to specify MaxLines. This will be available in a near-future Xamarin.Forms version on iOS, Mac OS, Android, and UWP.
What can you do with MaxLines
With the new property MaxLines, you can specify how much lines of text a Label should show at the most. Until now, a Label in Xamarin.Forms either showed all lines or, with the relatively new LineBreakMode property, was truncated at the end of one line.
Now, with MaxLines, you can do both!
How does MaxLines work?
It’s very easy, it’s added as a new property on the Label. Simply do something like this:
The above code will now result in something like the screenshot underneath. This app is the “internal” Forms app to test all kinds of features of the Xamarin.Forms capabilities. As you might notice, not much work went into designing… 😉
You can see how the long text is now spread over two lines. Any longer text will still be in the property, but not shown on the screen. When used in conjunction with LineBreakMode you can now create a Label that is neatly cut off at the end with some ellipsis.
In the above screenshot you can see the same functionality on Android and see that we get the ellipsis at the end when using it with LineBreakMode.TailTruncation.
Wherever possible you can also set it to automatic to let the Label grow as your text needs. For instance, on iOS, Mac OS
This feature just got merged at the time of writing, so don’t expect it to be in there this minute. But I’m sure it will be part of a upcoming release. In the meantime you could check out the pre-release packages or nightly builds. Also, keep your eye on the release notes to see this pop up.
If you have anything you’d like to discuss regarding contributing or this specific feature, please don’t hesitate to reach out!