Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Span Label underline is not working on Xamarin iOS

I'm using a Label with Spans, one of them is a link and I want to add an underline style, I'm using <Span Text="Link url" TextDecorations="Underline" /> but it is not working in iOS with "Xamarin.Forms" Version="5.0.0.2401".

I have tried to add an effect but all the properties needs to be set again (Styles, touch events, etc...).

<Label>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Text 1"/>
            <Span Text="Text 2"/>
            <Span Text="Click to open Link" TextDecorations="Underline">
                <Span.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding lINKCommand}"/>
                </Span.GestureRecognizers>
            </Span>
        </FormattedString>
    </Label.FormattedText>
</Label>

In some time Xamarin forms needs to fix it, meanwhile I want to apply a small temporal fix.

like image 207
Gerardo Enrique Ake Dzib Avatar asked Dec 11 '25 21:12

Gerardo Enrique Ake Dzib


1 Answers

I discovered that it works when set TextType property to Html in the Label at runtime.

So I had to create a data trigger and use a data binding to set when all data is loaded.

<Label>
    <Label.Triggers>
        <DataTrigger TargetType="Label" Binding="{Binding IsBusy}" Value="false">
            <Setter Property="TextType" Value="Html" />
        </DataTrigger>
    </Label.Triggers>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Text 1"/>
            <Span Text="Text 2"/>
            <Span Text="Click to open Link" TextDecorations="Underline">
                <Span.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding lINKCommand}"/>
                </Span.GestureRecognizers>
            </Span>
        </FormattedString>
    </Label.FormattedText>
</Label>
like image 69
Gerardo Enrique Ake Dzib Avatar answered Dec 13 '25 19:12

Gerardo Enrique Ake Dzib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!