David Clarke
David Clarke

Reputation: 13266

Format two labels to wrap in Xamarin Forms as single line

I have a xaml user registration page in a Xamarin Forms app where I want the user to accept the terms and conditions of use. I've used two labels in a horizontal stacklayout so that I can make the "terms and conditions" tappable to navigate to the terms and conditions page. It looks fine on an iPhone 6 and up:

enter image description here

But on a 5s it wraps as below:

enter image description here

The xaml for the controls:

<StackLayout Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Padding="0,0,0,5">
    <Label Text="I agree to the" VerticalOptions="Center" HorizontalOptions="Start" />
    <Label Text="terms and conditions" VerticalOptions="Center" HorizontalOptions="Start" LineBreakMode="WordWrap" >
        <Label.TextColor>
            <OnPlatform x:TypeArguments="Color"
                iOS="#0076fa"
                Android="#3d5afe" />
        </Label.TextColor>
        <Label.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding TermsCommand}" />
        </Label.GestureRecognizers>  
    </Label>
    <Switch IsToggled="{Binding Agree}" HeightRequest="30" WidthRequest="50" HorizontalOptions="Start" VerticalOptions="Center" />
</StackLayout>

Is there anyway to format all the text to wrap as a single sentence would?

Upvotes: 0

Views: 1655

Answers (1)

Depechie
Depechie

Reputation: 6142

I would suggest you create a custom label control to handle this! There is a very good starting point available up on the blog of Pieter Nijs here https://blog.pieeatingninjas.be/2017/11/05/creating-a-hyperlinklabel-in-xamarin-forms/ which looks like would be enough for your needs.

In short he created a label control that accepts markup text to be displayed on screen, meaning you can have hyperlinks available for only a portion of the text!

Technically it will transform the text on each platform to a control that can handle hyperlinks.

Upvotes: 0

Related Questions