How to make Label Text Underline?

Hassaan picture Hassaan · Mar 24, 2014 · Viewed 54.6k times · Source

How can I make Label text Underline in WPF? I am stucked and could not find any property for underline:

<Label Name="lblUserName"
       Content="Username"
       FontSize="14" FontWeight="Medium" />

Answer

Anatoliy Nikolaev picture Anatoliy Nikolaev · Mar 24, 2014

In Label no TextDecorations, therefore try this:

<Label Width="100" Height="30">
    <TextBlock TextDecorations="Underline">TestText</TextBlock>
</Label>

Edit: more universal solution

In this case, instead of Label.Content using Label.Tag, because Content property can be set only once:

<Label Tag="TestContent" 
       Width="100" 
       Height="30"
       HorizontalContentAlignment="Center"
       Background="AliceBlue">

    <TextBlock TextDecorations="Underline" 
               Text="{Binding Path=Tag, 
                              RelativeSource={RelativeSource Mode=FindAncestor,
                                                             AncestorType={x:Type Label}}}" />
</Label>