xaml - 为什么 TextBlock 会修剪文本中的结尾空格?

标签 xaml windows-8 microsoft-metro .net-4.5

这是我的 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>
这是输出(屏幕截图):
enter image description here
为什么TextBlock修剪结尾空格?但是,当有前导空格时它工作正常。

最佳答案

它看起来像 xml:space="preserve"应该可以解决问题(请参阅 Preserving Whitespace in XAML ),但这似乎不适用于 Windows Store 应用程序(它适用于 WPF)。

如果您使用不间断空格字符 &#160;它确实有效

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

我想您可以尝试在 Text 上构建转换器检查尾随空格并替换为不间断空格的属性 - 假设正在发生的截断不会发生得太早。

关于xaml - 为什么 TextBlock 会修剪文本中的结尾空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14337623/

相关文章:

c# - WPF 数据变化动画

c# - ActivityIndi​​cator 未在绑定(bind)到 ViewModel 的 XAML 中显示

xaml - 如何使用 C# 和 XAML 在 Metro 中的 Canvas 上绘图

c# - AuthenticationToken 为空

javascript - 将 Forecast.io 中的 JSONP API 与 WinJS 结合使用

c++ - MediaElement捕获麦克风并修改数据

c# - 为什么这种简单的风格不适用?

windows-8 - WinJS 在表格中渲染 listView

javascript - 如何重构if-else代码段?

c# - 使用 WPF 将一个列表与另一个列表绑定(bind)