Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set TextBlock to preserve white space at the beginning and at the end?

Tags:

EDIT:

The code below actually works as I want - this question a little misleading. Please ignore it.


Normally when I set Text property of TextBlock like this:

TextBlock tb = new TextBlock(); tb.Text = "     Hello World "; 

The whitespace at the beginning and at the end of text are not shown. The text shown by TextBlock is only Hello World. How can I set TextBlock to display them (i.e., not remove the whitespace)? Am I missing some property?

like image 545
Rasto Avatar asked May 09 '11 07:05

Rasto


People also ask

How do you preserve whitespace?

The HTML <pre> tag defines preformatted text preserving both whitespace and line breaks in the HTML document. This tag is also commonly referred to as the <pre> element.

What is white spacing?

Alternatively referred to as spacing or whitespace, white space is any section of a document that is unused or space around an object. White spaces help separate paragraphs of text, graphics, and other portions of a document, and helps a document look less crowded.

What is white space in code?

Whitespace refers to characters which are used to provide horizontal or vertical space between other characters. Whitespace is often used to separate tokens in HTML, CSS, JavaScript, and other computer languages.

How do I give space in XAML?

There are several techniques for preserving white space in the source XAML for eventual presentation that are not affected by XAML processor white-space normalization. xml:space="preserve": Specify this attribute at the level of the element where white-space preservation is desired.


1 Answers

In this case you don't need to use xml:space="preserve"

<TextBlock xml:space="preserve" Text="     Hello world!    " /> 

WILL display the whitespaces, however

<TextBlock>    Hello world!    </TextBlock> 

won't.

like image 111
Danield Avatar answered Sep 24 '22 09:09

Danield