3

I prepare some data for the sharing:

        package = package ?? new DataPackage();

        package.Properties.Title = "Event: " + data.Name;

        var text = new StringBuilder().AppendFormat(@"
Start at.   {0:F}<br/>
End at.     {1:F}<br/>
Total time. {2}<br/>
", data.StartTime, data.EndTime, data.TotalTime);


        var textHtml = text.ToString();
        package.SetText(textHtml.Replace("<br/>", ""));
        package.SetHtmlFormat(textHtml);

The like breaks shown fine in some apps (eg. Tweetro), but ignored in Mail. Any ideas how this can be fixed?

ie.
  • 5,982
  • 1
  • 29
  • 44

2 Answers2

0

You provide both Text and Html to the package.

So depending on what the target app accepts, it will use Text or Html. In your Text, your replace <br/> by an empty string. So you won't have line break.

Have you tried replacing by "\n" instead ? '\n' is the caracter for new line.

    package.SetText(textHtml.Replace("<br/>", "\n"));
Renaud Dumont
  • 1,776
  • 13
  • 24
  • I'm using `@-quoting`, new lines in my code will be in the string also, so I will have line breaks. – ie. Oct 23 '12 at 22:22
  • Indeed, my mistake ! I tried different ways and normally line breaks should appear. Anyway, when you share something, it's up to the target app to handle what you send. And if that apps wants to remove line breaks to show an in-line string, you can't do nothing. – Renaud Dumont Oct 24 '12 at 08:31
  • I see, but in my case I don't care about some hypothetical app. I need to force Mail to leave line breaks – ie. Oct 24 '12 at 09:54
0

I see I'm late to the party here, but I've had the same issue.

I found this SO - How to add new line while sharing text in WinRt which made me add the HtmlFormatHelper.CreateHtmlFormat(textToShare) when adding the HTML based text. That fixed the line breaks on the Mail app for me, because then it started using the HTML.

package.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(textHtml));

I think that the Mail app doesn't use HTML content unless it's correctly formatted, and the HtmlFormatHelper seems to do that.

Community
  • 1
  • 1
dylansturg
  • 1,698
  • 15
  • 17