无法在Windows 10中使用DataTransferManager共享图像 [英] Unable to share image using DataTransferManager in Windows 10

查看:199
本文介绍了无法在Windows 10中使用DataTransferManager共享图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求:使用 DataTransferManager 在Windows 10中的Facebook共享文本和图像。

Requirement: Share a text and image using DataTransferManager into Facebook in Windows 10.

问题:无法分享图片。

下面显示的是我使用的代码,

Below shown is the code I used,

 private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            DataRequestDeferral deferral = args.Request.GetDeferral();
            args.Request.Data.Properties.Title = "Sharing sample";
            args.Request.Data.SetText("Testing share in universal app");
            var imageUri = "http://cdn.vrworld.com/wp-content/uploads/2015/01/microsoft-announces-windows-10_ahab.1920.jpg";

            //var storageFile = await StorageFile.CreateStreamedFileFromUriAsync("ShareFile", new Uri(imageUri), null);
            //List<IStorageItem> storageItems = new List<IStorageItem>();
            //storageItems.Add(storageFile);
            //args.Request.Data.SetStorageItems(storageItems);

            args.Request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)));
            deferral.Complete();
        }

当我使用 SetBitmap 方法,只有标题和文本被共享。图像既不显示在共享面板中也不会共享到目标应用程序。

When I use SetBitmap method, only the title and text are being shared. The image is neither displayed in the share panel nor shared to the target app.

当我使用 SetStorageItems (见评论的代码),没有任何项目被共享。默认的你在想什么文本显示在共享面板上。

When I use SetStorageItems (see commented code), none of the items are shared. The default "What's on your mind" text appears on the share panel.

任何反馈都表示赞赏,谢谢!

Any feedback is appreciated, thank you!

推荐答案

不幸的是不支持共享URI流文件。以下是我如何做:

Sharing of URI streamed files is unfortunately not supported. Here's how I would go about doing this:


  1. 当用户单击共享按钮时,开始下载文件
    并显示一些如果它是一个大文件,进度如何。当然也可以
    预先下载文件。设置包含该文件的 StorageFile 实例

  2. 调用 DataTransferManager.ShowShareUI

  3. 在您的 DataRequested 处理程序,使用 SetStorageItems 共享 StorageFile 实例。

  1. When the user clicks the share button, start downloading the file and show some sort of progress if it's a big file. You could also pre-download the file of course. Set up a StorageFile instance containing the file.
  2. Call DataTransferManager.ShowShareUI
  3. In your DataRequested handler, use SetStorageItems to share the StorageFile instance.

这篇关于无法在Windows 10中使用DataTransferManager共享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆