Nie*_*eAR 2 wpf xaml newline textblock
有一些资源标记( 类似于 \r\n)
<Application.Resources>
<system:String x:Key="key1">Line1
Line2</system:String>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
对于主窗口:
<Grid>
<TextBlock Text="{DynamicResource key1}"/>
<Grid>
Run Code Online (Sandbox Code Playgroud)
但结果只有一行:“Line1 Line2”。怎么了?
只需xml:space="preserve"
像这样设置字符串资源,它就会按预期工作 -
<system:String xml:space="preserve" x:Key="key1">Line1
Line2</system:String>
Run Code Online (Sandbox Code Playgroud)