2013-04-22 75 views
6

所以,我有以下几点:换行或回车

<TextBlock.Text> 
    <MultiBinding StringFormat="So and so will donate {0:C0}&#x0d;&#x0a;to {1}, bringing the&#x0d;&#x0a;total amount to {2:C0}."> 
    <Binding Path="VisitorTotal" /> 
    <Binding Path="EventName" /> 
    <Binding Path="EventTotal" /> 
    </MultiBinding> 
</TextBlock.Text> 

我试过&#x0d;&#x0a;&#10;\n\\n,以及各种组合于此。没有什么会给我一个换行符。这是怎么回事?

+0

只是' '*应该*工作 - 你可以显示TextBlock的完整声明?你有套吗? – 2013-04-22 21:22:28

+0

我确实把它设置为实际包裹。有趣的是,这会产生影响。 – 2013-04-23 14:18:30

回答

16

我的选择是直接使用Environment.NewLine

<MultiBinding StringFormat="So and so will donate {0:C0}{3}to {1}, bringing the{3}total amount to {2:C0}."> 
    <Binding Path="VisitorTotal" /> 
    <Binding Path="EventName" /> 
    <Binding Path="EventTotal" /> 
    <Binding Source="{x:Static System:Environment.NewLine}"/> 
</MultiBinding> 

但是,你还需要确保TextBlock.TextWrapping设置为合适。

+0

太棒了。聪明。无可挑剔。 – 2013-04-22 21:38:12

+1

添加xmlns:s =“clr-namespace:System; assembly = mscorlib”(我将System更改为s以避免多个“System”字在命名空间定义中)。从LPL回答在[这个SO问题]中回答(http://stackoverflow.com/questions/183406/xaml-newline-in-string-attribute) – NGI 2015-10-22 15:30:58