How to make the signature text a label?

How can I make Label text Underline in WPF? I was stuck and could not find the property to underline:

 <Label Name="lblUserName" Content="Username" FontSize="14" FontWeight="Medium" /> 
+8
wpf xaml label underline
source share
2 answers

In Label no TextDecorations , try the following:

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

Edit: more universal solution

In this case, Label.Content used instead of Label.Content , because the Content property can only be set 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> 
+27
source share

Here is the answer with styles.

Content:

 <Label> <TextBlock Style="{DynamicResource StyleName}">text content</TextBlock> </Label> 

And style:

 <Style x:Key="StyleName"> <Setter Property="TextBlock.TextDecorations" Value="Underline" /> <Setter Property="TextBlock.FontStyle" Value="Italic" /> </Style> 
+3
source share

All Articles