Xaml 为什么TextBlock会从文本中修剪结束空格?

Xaml 为什么TextBlock会从文本中修剪结束空格?,xaml,windows-8,microsoft-metro,.net-4.5,Xaml,Windows 8,Microsoft Metro,.net 4.5,以下是我的TextBlocks: <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&

以下是我的
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>

以下是输出(屏幕截图):

为什么
TextBlock
会修剪结尾空格?但是,当有前导空格时,它可以正常工作。

尝试使用
xml:space=“preserve”


看起来
xml:space=“preserve”
应该可以做到这一点(请参阅),但这在Windows应用商店应用程序中似乎不起作用(在WPF中起作用)

如果使用不间断空格字符
 它确实有效

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

<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
    <TextBlock FontFamily="Segoe UI" Foreground="#000000" FontSize="13">
        <Run Text="6 or more characters, at least one letter and a number, " />
        <Run Text="no symbols" />
    </TextBlock>
</StackPanel>

而且单词包装仍然有效

<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
    <TextBlock FontFamily="Segoe UI" Foreground="#000000" FontSize="13" 
        Width="200" TextWrapping="Wrap">
        <Run Text="6 or more characters, at least one letter and a number, " />
        <Run Text="no symbols" />
    </TextBlock>
</StackPanel>

如果包装不是问题,我会很容易地使用吉姆的解决方案


在您的脑海中,请思考HTML如何处理和保留空间。这也是XAML处理和保留空间的方式。当然,你会想,在文本块中,它会被更准确地处理,是吗?嗯,就是这样。至少有一个解决方案。

RichTextBlock似乎同时保留了前导和尾随空格(在WP 8.1 WinRT中):



但它似乎也在您指定的运行之间添加了额外的空间。

我找到了一个不同的解决方案!当您还设置了
IsTextSelectionEnabled
时,
\u+A0
起作用

我不知道为什么会这样,这完全是一个惊喜(我添加了这个字段,因为我刚刚发现了它,同时还在研究我的“为什么我的文本在通用应用程序中被修剪?”问题)


此外,
U+205F
(中等数学空间)也可与空间属性的
IsTextSelectionEnabled

+1一起使用。但这在存储应用程序中不起作用不破坏空格可以起作用,但
空格
属性很容易做到:(从WinRT 8.1更新。
xml:space
仍然不起作用,而此解决方案确实起作用。这(使用 ;)当前在Windows 10通用应用程序上似乎不起作用。我必须将其设置为开头和结尾标记之间的内容,而不是设置文本属性以使其正确呈现。尝试了许多其他变体,但均无效(\u0020,#nbsp,等等)Jerry我为什么要这样做是因为当我的应用程序处于正常模式时,文本应该是
6个或更多字符,至少一个字母和一个数字,没有符号,而在快照查看模式下,文本应该是
6个或更多字符,至少一个字母和一个数字,没有符号。我已经这样做了。但我希望这些文本应该来自m
.resw
文件。换句话说,我应该如何设置
中的文本,就像
我发布了一个相同的
从2016-10-06起,IsTextSelectionEnabled技巧不再起作用,
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
    <TextBlock FontFamily="Segoe UI" Foreground="#000000" FontSize="13" 
        Width="200" TextWrapping="Wrap">
        <Run Text="6 or more characters, at least one letter and a number, " />
        <Run Text="no symbols" />
    </TextBlock>
</StackPanel>
<RichTextBlock>
 <RichTextBlock.Blocks>
  <Paragraph >
   <Paragraph.Inlines>
    <Run Text="trailing " /><Run Text="bbb" /><Run Text=" leading" />
   </Paragraph.Inlines>
  </Paragraph>
 </RichTextBlock.Blocks>
</RichTextBlock>