Xamarin Formats - Truncate Multiline Text

Truncating label text makes it a single line. The application shows a description, it should be displayed in 2-3 lines, but Xamarin " LineBreakMode = TailTruncation " truncates it and limits it to one line. Is there a way to crop label text and show in multi-line lines. If the text does not fit into n number of lines, it should be truncated.

<Label LineBreakMode="TailTruncation" FontSize = "20" Text="Multi line Text" /> 

Thanks.

+5
source share
1 answer

I applied a 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); } }; } } 
+1
source

All Articles