gpt4 book ai didi

wpf - 在 WPF 中为字符串资源添加回车

转载 作者:行者123 更新时间:2023-12-03 21:15:09 25 4
gpt4 key购买 nike

我的应用程序按照此处的建议将所有本地化文本存储在字符串资源字典中 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 中使用它时正确呈现它。

执行此内联工作:
<TextBlock Name="test" Text="Line 1&#13;Line 2"> </TextBlock>

但是,使用 &#13;在字符串资源中不起作用。向字符串资源添加新行的最佳方法是什么?

最佳答案

更新:更新的答案 - 更好的选择

XAML 解析器根据以下规则对空格进行规范化。

http://msdn.microsoft.com/en-us/library/cc189036(VS.95).aspx#whitespace

指导您的sys:String要保留空格,请应用 xml:space="preserved给它:

<sys:String x:Key="MyLocalizedString" xml:space="preserve">this&#13;&#10;is&#13;&#10;my&#13;&#10;resource</sys:String>

关于wpf - 在 WPF 中为字符串资源添加回车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3973985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com