为什么TextBlock会修剪文本的结尾空格? [英] Why does TextBlock trims ending spaces from the text?

查看:121
本文介绍了为什么TextBlock会修剪文本的结尾空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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).

如果您使用不间断的空格字符&#160;,它将起作用

If you use the non-breaking space character &#160; it does work

 <TextBlock Text="6 or more characters, at least one letter and a number,&#160;&#160;&#160;&#160;&#160;&#160;&#160;"  ....

我想您可以尝试在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆