Truncate the label text makes it one line. App shows description, it needs to be displayed in 2-3 lines but Xamarin "LineBreakMode=TailTruncation" truncates it and restricts it to one line. Is there any way to truncate label text and show in multi-lines. If text doesn't fit into n number of lines, then it should be truncated.
<Label LineBreakMode="TailTruncation" FontSize = "20" Text="Multi line Text" />
Thanks.
A StackLayout organizes child views in a one-dimensional stack, either horizontally or vertically. By default, a StackLayout is oriented vertically. In addition, a StackLayout can be used as a parent layout that contains other child layouts.
To display local content using a WebView , you'll need to open the HTML file like any other, then load the contents as a string into the Html property of an HtmlWebViewSource .
Since Xamarin.Forms 3.3 a new property was introduced for this feature. It's called MaxLines
.
Here is an example in C#:
var yourLabel = new Label
{
LineBreakMode = LineBreakMode.TailTruncation,
Text = "Your text",
MaxLines = 2
};
Here is an example in XAML:
<Label
LineBreakMode="TailTruncation"
Text="Your text"
MaxLines="2" />
See https://docs.microsoft.com/de-de/dotnet/api/xamarin.forms.label.maxlines?view=xamarin-forms for more information.
I have implemented custom renderer to handle this.
http://depblog.weblogs.us/2016/06/27/xamarin-forms-multi-line-label-custom-renderer-gotcha/
//Droid
public class MultiLineLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.LayoutChange += (s, args) =>
{
Control.Ellipsize = TextUtils.TruncateAt.End;
Control.SetMaxLines(2);
}
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With