Home > OS >  Span Label underline is not working on Xamarin iOS
Span Label underline is not working on Xamarin iOS

Time:05-07

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.

CodePudding user response:

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>

CodePudding user response:

I have also discovered that it works when You set FontSize in Label at runtime.

  • Related