在 WPF 中为字符串资源添加回车 [英] Add carriage return to string resource in WPF
问题描述
我的应用程序按照此处的建议将所有本地化文本存储在字符串资源字典中 http://msdn.microsoft.com/en-us/library/bb295251(VS.85).aspx
My applications store all localized text in a string resource dictionary as suggested here http://msdn.microsoft.com/en-us/library/bb295251(VS.85).aspx
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- String resource that can be localized -->
<system:String x:Key="localizedMessage">en-US Message</system:String>
</ResourceDictionary>
我的问题是,如何向字符串资源添加新行并使其在 TextBlock 中使用时正确呈现.
My question is, how can I add a new line to a string resource and have it render correctly when it's used in a TextBlock.
执行此内联工作:
<TextBlock Name="test" Text="Line 1 Line 2"> </TextBlock>
但是,在字符串资源中使用
不起作用.向字符串资源添加新行的最佳方法是什么?
However, using
in a string resource does not work. What's the best way to add a new line to a string resource?
推荐答案
更新:更新的答案 - 更好的选择
UPDATE: updated answer - better option
XAML 解析器根据以下规则规范化空格.
The XAML parser normalized whitespace according to the following rules.
http://msdn.microsoft.com/en-us/library/cc189036(VS.95).aspx#whitespace
要指示您的 sys:String
保留空格,请将 xml:space="preserved
应用到它:
To instruct your sys:String
to preserve whitespace, apply xml:space="preserved
to it:
<sys:String x:Key="MyLocalizedString" xml:space="preserve">this is my resource</sys:String>
这篇关于在 WPF 中为字符串资源添加回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!