Samantha J T Star
Samantha J T Star

Reputation: 32798

How can I center a label now that XAlign is no longer supported?

Here's the code I was using:

 <Label x:Name="detail3" Grid.Row="2" FontSize="35" XAlign="Center" VerticalOptions="Center" LineBreakMode="WordWrap" />

But I understand XAlign should no longer be used.

Upvotes: 0

Views: 437

Answers (3)

JKennedy
JKennedy

Reputation: 18799

XAlign has been deprecated for the better named HorizontalTextAlignment

Similarly YAlign has been deprecated for VerticalTextAligment

So to horizontal align the text for your Label you can do the following:

<Label x:Name="detail3" Grid.Row="2" FontSize="35" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"  LineBreakMode="WordWrap" /> 

See https://developer.xamarin.com/api/type/Xamarin.Forms.Label/

HorizontalTextAlignment

Center, End, or Start, to indicate the horizontal placement of the label text.

VerticalTextAlignment

Center, End, or Start, to indicate the vertical placement of the label text.

Upvotes: 7

Pratius Dubey
Pratius Dubey

Reputation: 673

If you want to Label control in centre align use the -HorizontalOptions="Centre"

<Label x:Name="detail3" Grid.Row="2" FontSize="35" XAlign="Center" VerticalOptions="Center" HorizontalOptions="Centre"  LineBreakMode="WordWrap" />

If you want to Label's text in centre align use the -HorizontalTextAlignment="Centre"

<Label x:Name="detail3" Grid.Row="2" FontSize="35" XAlign="Center" VerticalOptions="Center" HorizontalTextAlignment="Centre"  LineBreakMode="WordWrap" />

Upvotes: -1

Jackson
Jackson

Reputation: 5

Please check Xamarin documentation Xamarin.Forms.Label.XAlign Property

Upvotes: 0

Related Questions