Omortis
Omortis

Reputation: 1530

How do I center multiline text in a label

Has anyone figured out how to center (or justify or in any way horizontally effect) text in a Xamarin Forms Label with LineBreakMode=WordWrap? Without using a WebView (or similar)?

All HorizontalOptions entries are cheerfully ignored in this code snippet:

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

It looks like this.

Upvotes: 3

Views: 2556

Answers (2)

Chetan Rawat
Chetan Rawat

Reputation: 588

add this line in your code

HorizontalTextAlignment="Center"

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        HorizontalTextAlignment="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

Upvotes: 0

Adlorem
Adlorem

Reputation: 1507

You should use HorizontalTextAlignment="Center" in this case.

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        HorizontalTextAlignment="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

Upvotes: 5

Related Questions