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?
You can break the text with <Run> tag and then surround only the text part that you want underlined with <Underline>.
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.
To underline a text in HTML, use the <u> tag.
You should use the property "TextDecorations" of the TextBlock. Like that:
<TextBlock Text="H" TextDecorations="Underline"/>
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.
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