我有Image Urls
&列表我希望Share
一次Windows 8 share charm
这些图片[来自每个网址]。{
这是我用来一次共享一个WriteableBitmap Image
的代码。
var dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += DataRequested;
public void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
DataRequestDeferral deferral = request.GetDeferral();
try
{
request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(ImageUrl)));
}
}
我们如何通过share a multiple images
Share Charm
一次{{1}}。
我们可以分享图像和文字的组合吗?
如果有可能,请告诉我。
答案 0 :(得分:3)
更新1
下面的代码显示了如何通过共享魅力共享多个图片网址。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += DataRequested;
}
public void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var Images = new List<string>
{
"http://jenswinter.com/image.axd?picture=stackoverflow-logo-250.png",
"http://en.flossmanuals.net/thunderbird/getting-support/_booki/thunderbird/static/Thunderbird-Support-tbird_support_superuser-en.jpg",
"http://www.thomas-steinbrenner.net/wp-content/uploads/2010/11/Stackexchange_logo.png"
};
var res = GetHtml(Images);
DataRequest request = args.Request;
// The title is required. Otherwise it won't be shared.
request.Data.Properties.Title = "Multi Image via Share Charm Using HTML.";
DataRequestDeferral deferral = request.GetDeferral();
try
{
string htmlFormat = HtmlFormatHelper.CreateHtmlFormat(res);
request.Data.SetHtmlFormat(htmlFormat);
}
catch { }
finally { deferral.Complete(); }
}
private string GetHtml(List<string> ImageUrls)
{
string ImgTag = @"<img src='{0}' /><br />";
string Html = @"<html>
<head>
<title>Multi Image via Share Charm</title>
</head>
<body>
{0}
</body>
</html>";
string AllImgTags = "";
foreach (var url in ImageUrls)
{
AllImgTags += string.Format(ImgTag, url);
}
return string.Format(Html, AllImgTags);
}
如果所有都是互联网网址,那么您可以通过从这些网址创建HTML文档来共享它。如果您有多个StorageFile
,则可以与DataPackage.SetStorageItems
分享。它接受IEnumerable<IStorageItem>
。
DataPackage.SetBitmap
一次只接受一个位图,因为通常接受图片的目标应用主要处理单个图像。如果应用需要多张图片,我建议您使用DataPackage.SetStorageItems