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

后端 未结 3 1263
不思量自难忘°
不思量自难忘° 2021-02-05 05:45

EDIT:

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


Normally when I set Text property of <

相关标签:
3条回答
  • 2021-02-05 06:26

    Re: "I just hope you are not using this to align your text. There are many other more elegant methods to do so."

    Sounds like you might want to use the Padding property: http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.padding(VS.85).aspx.

    See also the various alignment & margin properties.

    0 讨论(0)
  • 2021-02-05 06:27

    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.

    0 讨论(0)
  • 2021-02-05 06:44

    set the xml:space property to preserve in your XAML, i assume you are using WPF

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

    EDIT: It is sometimes easier to do things in XAML. I just hope you are not using this to align your text. There are many other more elegant methods to do so.

    0 讨论(0)
提交回复
热议问题