在Windows Phone 8.1 C#WinRT(共享合同)中共享HTML内容

时间:2015-12-16 10:51:06

标签: c# windows-runtime windows-phone-8.1

我有需要分享的HTML代码。当我在Windows桌面/笔记本电脑(Winrt)上运行以下代码时,它会在outlook或gmail应用程序中显示数据和图像,但是当我尝试在Windows Phone 8.1上共享时,它只显示标题但不显示html内容。< / p>

DataTransferManager manager = null;

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    manager = DataTransferManager.GetForCurrentView();
    manager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(share_DataRequested);
}

private void share_DataRequested(object sender, DataRequestedEventArgs e)
{
    DataRequestDeferral deferral = e.Request.GetDeferral();

    DataRequest request = e.Request;
    request.Data.Properties.Title = "This is my Title";
    request.Data.Properties.ApplicationName = "App Name";

    StringBuilder builder = new StringBuilder();

    builder.Append("<img src='URI_Image' title='something' /> ");       
    builder.Append("<pre style='font-family:Helvetica'>some data</pre>");

    request.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(builder.ToString()));

    deferral.Complete();

}

private void Button_Click(object sender, RoutedEventArgs e)
{
    DataTransferManager.ShowShareUI();
}

Demo App Download Link

我该如何解决这个问题..

1 个答案:

答案 0 :(得分:0)

尝试将您的代码更改为:

var builder = new StringBuilder();
builder.Append(@"<!DOCTYPE html>");       
builder.Append(@"<html itemscope itemtype="http://schema.org/QAPage">");
builder.Append(@"<head>");
builder.Append(@"<title>My web page</title>");
builder.Append(@"</head>");
builder.Append(@"<body>");
builder.Append(@"<img src="URI_Image" title="something" /> ");       
builder.Append(@"<pre style="font-family:Helvetica">some data</pre>");
builder.Append(@"</head>");
builder.Append(@"</body>");
builder.Append(@"</html>");