#812 – Use TextDecorations Property to Underline or Strike Through Text

Some controls that render text include a TextDecorations property that allows you to underline the text or draw a line through the middle of the text.

The allowed values of the TextDecorations property are:

  • Underline – Underline the text (line appears just a bit below the bottom of the characters)
  • Baseline – Draw a line that runs along the bottom edge of the characters (just above where the underline would appear)
  • StrikeThrough – Draw a line through the middle of the characters
  • Overline – Draw a line over the top edge of the characters

Below is an example of the TextDecorations property used with the TextBlock control.  TextDecorations is not supported for Labels.

        <TextBlock Text="Underline pphh" Padding="20,10" FontSize="16"
        <TextBlock Text="Baseline pphh" Padding="20,10" FontSize="16"
        <TextBlock Text="StrikeThrough pphh" Padding="20,10" FontSize="16"
        <TextBlock Text="Overline pphh" Padding="20,10" FontSize="16"



#245 – Easily Inline Text Formatting Codes with TextBlock Control

You can specify a TextBlock control’s content by defining a series of Run elements.

You can also just specify the text by setting the child element of the TextBlock:

			Henry V was here.

Finally, you can include some formatting tags directly in the body of the text:

		<TextBlock Margin="10" Height="100" FontSize="14" Width="290" TextWrapping="Wrap">
			We <Bold>few</Bold>, we happy <Bold>few</Bold>, we band of <Underline>brothers</Underline>;
For he to-day that sheds his <Italic>blood</Italic> with me
Shall be my <Underline>brother</Underline>; be he ne'er so <Italic>vile</Italic>,
This day shall <Bold>gentle</Bold> his <Italic>condition</Italic>;"