Accessibility link on Xamarin
Links should be accessible for users of assistive technologies. When accessibility is not taken into account, users might not be able to find or activate links.
In Xamarin, you need to follow four steps to create links:
Set the
TextColor
andTextDecoration
properties of theLabel
orSpan
.Add a
TapGestureRecognizer
to theGestureRecognizers
collection of theLabel
orSpan
, whoseCommand
property binds to aICommand
, and whoseCommandParameter
property contains the URL to open.Define the
ICommand
that will be executed by theTapGestureRecognizer
.Write the code that will be executed by the
ICommand
.
For more information, see Xamarin Hyperlinks, it includes information how you can create your own Hyperlink class.
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="Read more about " />
<Span Text="Appt"
TextColor="Blue"
TextDecorations="Underline">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}"
CommandParameter="https://appt.org" />
</Span.GestureRecognizers>
</Span>
</FormattedString>
</Label.FormattedText>
</Label>