1
votes

On a Xamarin.Forms label, I see a MinimumWidthRequest, but is there any way to set the maximum width allowed?

I have a StackLayout with horizontal orientation, and would like labels in the layout to have a maximum width of 500px before being truncated. I don't want to just set the WidthRequest to 500px, because shorter labels should be sized to fit without extra space at the end.

1

1 Answers

3
votes

Try setting the label's LineBreakMode to TailTruncation

If you do not set the WidthRequest, it will automatically truncate when the label reaches the end of the container. This will allow your shorter labels to remain smaller, as you requested.

XAML

<Label 
  Text="This is a very long text" 
  LineBreakMode="TailTruncation">
</Label>

C#

label.LineBreakMode = LineBreakMode.TailTruncation;

============