【问题标题】:Line breaks are being ignored when binding to a string StaticResource绑定到字符串 StaticResource 时将忽略换行符
【发布时间】:2012-01-20 01:37:20
【问题描述】:

我们正在开发一个 Windows Phone 7 应用程序,并有一个这样定义的 TextBlock:

<TextBlock Text="{StaticResource MY_TEXT}" TextWrapping="Wrap" Style="{StaticResource SubHeadingStyle}"/>

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

<system:String x:Key="MY_TEXT">This is the first line of text.&#13;This is the second line of text.</system:String>

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

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

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

【问题讨论】:

    标签: silverlight windows-phone-7 xaml


    【解决方案1】:

    你必须Preserve 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>
    

    【讨论】:

    • 是的,那个也难倒我...至于空间,这样做 
    猜你喜欢
    • 2010-10-16
    • 2019-05-26
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 2019-06-30
    • 2017-11-22
    • 2019-07-13
    • 2017-12-30
    相关资源
    最近更新 更多