绑定到字符串StaticResource时会忽略换行符

gra*_*rks 1 silverlight xaml windows-phone-7

我们正在开发一个Windows Phone 7应用程序并且具有如下定义的TextBlock:

<TextBlock Text="{StaticResource MY_TEXT}" TextWrapping="Wrap" Style="{StaticResource SubHeadingStyle}"/>
Run Code Online (Sandbox Code Playgroud)

我们有一个像这样定义的资源:

<system:String x:Key="MY_TEXT">This is the first line of text.&#13;This is the second line of text.</system:String>
Run Code Online (Sandbox Code Playgroud)

我们已经尝试了所有我们可以想到的方式来表示XML中的换行符,但无论我们尝试什么,它都要么被完全忽略,要么出现在TextBlock的屏幕上.

我们已经将问题隔离到加载资源字典 - 如果我们以编程方式从资源字典中读取字符串,则换行符已被空格字符(0x20)替换.相反,如果我们在XAML中的TextBlock的Text属性中放置一个换行符,它就会出现.

有没有什么办法可以让我们的TextBlock正确显示换行符,同时仍然使用绑定,而无需编写代码来修改值?

MyK*_*SKI 5

你必须保留WhiteSpace

<system:String xml:space="preserve" x:Key="PURCHASE_SUCCESS">This is the first line of text.&#13;This is the second line of text.</system:String>
Run Code Online (Sandbox Code Playgroud)