'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.
Solution 1:[1]
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>
Solution 2:[2]
I have also discovered that it works when You set FontSize in Label at runtime.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Blu |
Solution 2 | Marek Ku?niecow |