c# - 无法在 Windows 10 中使用 DataTransferManager 共享图像

标签 c# facebook windows-10 fileshare

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

问题:无法分享图片。

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

 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 方法时,只有标题和文本被共享。该图像既不显示在共享面板中,也不共享到目标应用。

当我使用 SetStorageItems(参见注释代码)时,没有任何项目是共享的。默认的“What's on your mind”文本显示在共享面板上。

欢迎任何反馈,谢谢!

最佳答案

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

  1. 当用户点击分享按钮时,开始下载文件 如果它是一个大文件,则显示某种进度。你也可以 当然要预先下载文件。设置一个 StorageFile 实例 包含文件。
  2. 调用DataTransferManager.ShowShareUI
  3. 在您的 DataRequested 处理程序中,使用 SetStorageItems 共享 StorageFile 实例。

关于c# - 无法在 Windows 10 中使用 DataTransferManager 共享图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30051700/

相关文章:

c# - Azure Web 角色启动时 IIS Express 失败

c# - .Net 正则表达式 : what is the word character\w?

c# - 序列化为 JSON 时排除集合中的特定项目

html - 如何将文本链接到 Facebook 评论中的超链接?评论插件

notifications - Windows 10 上未显示 Electron 桌面通知

vb.net - 在 WinRT、Windows8(10) 应用程序中获取 Windows 版本

带边界的 C# HTTP POST

android - 如何在 Android Studio 离线模式下添加 Facebook 依赖

android - Facebook 登录 sdk 在发布应用程序 android 中不起作用

python - 无法导入 cv2; "DLL load failed"