Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How can I prevent labels from taking up all available horizontal space when word wrapping?

$
0
0

I have labels inside a grid and I want them to take up only the necessary space to fit the text. With short messages this works correctly, but with longer messages that text wrap the label fills the available space even though the way the words wrapped means that it doesn't need it.

My account isn't allowed to post direct links yet but here is a screenshot:
photos.google.com/share/AF1QipNDOK7HtPb3rLREC2dhufaKCA9CnSpIqk-rRJTSSKQa-XO9c8UzNbHxVEMpfKlMOQ/photo/AF1QipMVZVv3ciXt9xafg_cfkVU68Te9_iwamMrWB7A6?key=ZDdjTnRpQkZaeWRfcU0yOXljZGNsTEdDS3p3XzdB

As you can see, the pink label takes up only the necessary amount of space, while the aquamarine one expanded to fill the available space despite having a large area on the right that doesn't have any text in it.

I've tried searching for solutions with no luck. The only thread I found that even mentions this problem has two developers bickering about whether or not the one trying to help actually understands what the problem is, and a solution is never posted. Does anyone know how to fix this?

XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="90"/>
</Grid.ColumnDefinitions>
<Label BackgroundColor="Aquamarine"
HorizontalTextAlignment="Left"
HorizontalOptions="Start"
Grid.Row="0" Grid.Column="0">
Hippopotamus vocabulary accentuates educational imbalances. Gymnastic crocodilians abbreviate gratuitously enourmous nomenclature.
</Label>
<Label BackgroundColor="Pink"
HorizontalTextAlignment="Left"
HorizontalOptions="Start"
Grid.Row="1" Grid.Column="0"
Margin="0,0,90,0">
Short.
</Label>
<StackLayout Grid.Row="0" Grid.Column="1" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand"></StackLayout>
<StackLayout Grid.Row="1" Grid.Column="1" BackgroundColor="Green" HorizontalOptions="FillAndExpand"></StackLayout>
</Grid>


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>