为什么TextBlock会修剪文本的结尾空格? [英] Why does TextBlock trims ending spaces from the text?
问题描述
这是我的TextBlock
s
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<TextBlock Text="6 or more characters, at least one letter and a number, " FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
<TextBlock Text="no symbols" FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
</StackPanel>
这是输出(屏幕截图)
And here is the output (screen shot)
为什么TextBlock
修剪结尾空格?但是,当我给空格时,它会很好地工作.
Why TextBlock
trims ending spaces? However it works fine when I give leading spaces.
推荐答案
xml:space="preserve"
应该应该可以解决问题(请参见
It looks like xml:space="preserve"
should do the trick (see Preserving Whitespace in XAML) but that doesn't seem to be working in a Windows Store app (it does in WPF).
如果您使用不间断的空格字符 
,它将起作用
If you use the non-breaking space character  
it does work
<TextBlock Text="6 or more characters, at least one letter and a number,       " ....
我想您可以尝试在Text
属性上构建一个转换器以检查尾随空格并替换为不间断空格-假设发生的截断不会太早发生.
I suppose you could try building a converter on the Text
property to check for trailing spaces and replace with non-breaking spaces - presuming the truncation that's happening doesn't occur too early.
这篇关于为什么TextBlock会修剪文本的结尾空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!