我们如何通过Windows 8共享魅力在c#中一次共享多个图像或图像与文本的组合

时间:2013-09-19 09:53:13

标签: c# windows-8 windows-runtime microsoft-metro winrt-xaml

我有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}}。
我们可以分享图像和文字的组合吗?
如果有可能,请告诉我。

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