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?
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.
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.
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.
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.
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.
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