Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBlock Underline

I have a textblock of width say 500, but my string is just say "H" but I want to underline the whole textblock width not just under H what can I do?

like image 917
user679530 Avatar asked Apr 09 '11 00:04

user679530


People also ask

How to underline TextBlock WPF?

You can break the text with <Run> tag and then surround only the text part that you want underlined with <Underline>.

How do I add a paragraph in TextBlock WPF?

Add(new Run("Text of paragraph.")); // Create a span with the content of the paragraph (FontSize 25 and FontWeight Bold stay alive) Span span = new Span(para. ContentStart, para. ContentEnd); // Create a TextBlock with the span (FontSize 25 and FontWeight Bold get lost) TextBlock textBlock = new TextBlock(); textBlock.

How do you underline a label in HTML?

To underline a text in HTML, use the <u> tag.


2 Answers

You should use the property "TextDecorations" of the TextBlock. Like that:

 <TextBlock Text="H" TextDecorations="Underline"/> 
like image 193
Talia H Avatar answered Sep 19 '22 08:09

Talia H


Just to add my 2 cents, The same effect as Talia's answer can be achieved at runtime through this code:

YourTextBlock.TextDecorations = System.Windows.TextDecorations.Underline; 

For some reason VS2010 doesn't show Intellisense for the RHS, but it compiles and runs correctly.

like image 45
dotNET Avatar answered Sep 20 '22 08:09

dotNET