How to underline label with underline effect in Xamarin Forms?

Xamarin Forms added a TextDecorations property to Labels. Update to Xamarin Forms 3.3.0+ and just set:

C#

Label label = new Label {
    TextDecorations = TextDecorations.Underline
}

XAML

<Label TextDecorations="Underline"/>

Docs Link

Be aware that there was a bug on iOS when an underlined Label is in a ListView. Looks like it has been fixed and released in 3.5.0. I am still using a custom renderer on iOS for now until I am ready to update to the latest version.

GitHub issue

So continue using the iOS effect if you have not updated to XF 3.5.0 yet.


Use TextDecorations property in Label class.

<Label Text="Underlined Text" TextDecorations="Underline"/>


The lengths some people are going to to get underlined text in Xamarin is insane. Here's a way to do it without a thousand line custom renderer. The negative margin trick came from this guy.

<StackLayout HorizontalOptions="Start">
    <Label Text="Underlined Text" />
    <BoxView HeightRequest="1" BackgroundColor="Purple" HorizontalOptions="FillAndExpand" Margin="0,-7,0,0" />
</StackLayout>