Newline or carriage returns in Multibind StringFormat
Asked Answered
B

1

9

So i've got the following:

<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>

I've tried &#x0d;&#x0a;, &#10;, \n, \\n, and various combinations thereto. Nothing will give me a newline. What's the deal?

Birefringence answered 22/4, 2013 at 21:17 Comment(2)
Just &#x0a; should work - Can you show the full declaration of the TextBlock? Do you have it set to wrap?Underprop
I do have it set to wrap actually. Interesting that that would have an effect.Birefringence
U
25

My preference is to use Environment.NewLine directly:

<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>

However, you'll also need to make sure the TextBlock.TextWrapping is set appropriately.

Underprop answered 22/4, 2013 at 21:21 Comment(2)
Awesome. Clever. Impeccable.Ellery
With adding xmlns:s="clr-namespace:System;assembly=mscorlib" for <Binding Source="{x:Static s:Environment.NewLine}"/> ( I change System to s to avoid multiple "System" words in the namespace definition ). Stolen from LPL answer in this SO questionTitlark

© 2022 - 2024 — McMap. All rights reserved.