Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring Text Decorations such as Underline, Strikethrough in a Style

How do I include text decorations such as Underline, Strikethrough etc in a Style definition:

<Style x:Key="UnderlinedLabel">      <Setter Property="Control.FontFamily" Value="Trebuchet MS" />      <Setter Property="Control.FontSize" Value="14" />      <!-- Next line fails -->      <Setter Property="Control.TextDecorations" Value="Underline" /> </Style> 

I'm familiar with using the following XAML to underline text:

<TextBlock>    <Underline>        Underlined text    </Underline> </TextBlock> 

However text decoration is just another style, I want to be able to define it declaritively like FontWeight, FontSize etc.

[Update]

I was applying this style to a Label control. This was my main problem. It appears you can't underline text in a Label. Change to a TextBlock (thanks gix) and all is well.

like image 939
Ash Avatar asked Feb 16 '09 04:02

Ash


People also ask

How do you underline text in style?

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.

What CSS property can be used to underline or strikethrough text?

text-decoration: The text-decoration property is used to add decoration to the text. This styling property is used to add decorations like underline, overline, and strikethrough. This property is also used as a shorthand property for the below list of text decorators.

What is style or text-decoration?

Definition and UsageThe text-decoration-style property sets the style of the text decoration (like solid, wavy, dotted, dashed, double). Tip: Also look at the text-decoration property, which is a short-hand property for text-decoration-line, text-decoration-style, text-decoration-color, and text-decoration-thickness.

Is underline a text-decoration?

All CSS text-decoration PropertiesSpecifies the kind of text decoration to be used (underline, overline, etc.) Specifies the style of the text decoration (solid, dotted, etc.)


1 Answers

Underlining text can be done either with <Underline>...</Underline> or with the TextDecorations attribute set to Underline. You can include the latter in a style definition:

<Style x:Key="Underlined">     <Setter Property="TextBlock.TextDecorations" Value="Underline" /> </Style>  <TextBlock Style="{StaticResource Underlined}">     Foo </TextBlock> 
like image 132
gix Avatar answered Sep 21 '22 13:09

gix