How to add new line while sharing text in WinRt

2019-06-25 09:42发布

问题:

I want to share some text using mail client on windows 8, in which I want to display new lines. It displays it correctly in notepad on using \r\n but doesn't work with the SetText function in DataTransferManager.

回答1:

The key is to set text in HTML and not send it as string.

Suppose the text you want to share is in string textToShare; Note that you will be sending a string in HTML, so you need to replace all new line characters with <br/>

instead of

theRequest.Data.SetText(textToShare);

use

theRequest.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(textToShare));