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" />
To underline a text in HTML, use the <u> tag. The <u> tag deprecated in HTML, but then re-introduced in HTML5. Now it represents a text different from another text stylistically, such as a misspelled word. To underline a text, you can also use the style attribute.
Select the text of the label, right click and change the font to 'underline'.
To add a text decoration to text, create a TextDecoration object and modify its properties. Use the Location property to specify where the text decoration appears, such as underline. Use the Pen property to specify the appearance of the text decoration, such as a solid fill or gradient color.
Build A Paint Program With TKinter and Python Sometimes, we need to style the font property of Label Text such as fontfamily, font-style (Bold, strike, underline, etc.), font-size, and many more. If we want to make the label text underlined, then we can use the underline property in the font attribute.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With