天天看点

wpf 换行符

方法1:
<TextBlock Text="第一行&#x0a;第二行"/>
文字中间加上:&#x0a;
就可以了。这个方法很有用,也可以用在ToolTip上:
<ToolTip Width="200" Content="'第一行' 
                   &#x0a;&#x0d;'第二行' 
                   &#x0a;&#x0d;'第三行'"/> 

方法2:
<TextBlock xml:space="preserve">
第一行
 第二行
</TextBlock>
 Preserve能保留xaml中的空格
 方法3:
<TextBlock Text="{Binding StringFormat='第一行{0}第二行{0}第三行',
                           Source={x:Static s:Environment.NewLine}}" />

      

<sys:String x:Key="NewUpdateWillShow" xml:space="preserve">第一行&#13;第二行&#13;</sys:String>

换行符为&#13;

必须加上xml:space="preserve",否则换行符无效。

<sys:String x:Key="txtEditorTipSrc" xml:space="preserve">第一行&#13;&#10;第二行</sys:String>

官方文档参考:

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