Ejemplo n.º 1
0
        private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            ShareSourceData shareSourceData = new ShareSourceData("AppDisplayName".GetLocalized());

            shareSourceData.SetWebLink(new Uri("https://www.microsoft.com/store/productId/9PD60ZWCB16K"));
            e.Request.SetData(shareSourceData);
        }
Ejemplo n.º 2
0
        // bw: 表示しているWebページの情報を共有へ送る
        // 以下のusingが必要
        //   using Sample01.Hamburger.CodeBehind.Helpers;
        //   using Sample01.Hamburger.CodeBehind.Models;
        //   using Windows.ApplicationModel.DataTransfer;
        private void ShareUrl()
        {
            // - Step 1. Setup a DataTransferManager object in your page / view and add a DataRequested event handler
            //   (i.e. OnDataRequested) to be called whenever the user invokes share.
            // ステップ1:DataTransferManagerオブジェクトを取得し、
            //            DataRequestedイベントハンドラーを設定する
            if (dataTransferManager == null)
            {
                dataTransferManager = DataTransferManager.GetForCurrentView();
                dataTransferManager.DataRequested += OnDataRequested;
            }

            // DataRequestedイベントハンドラー(内部関数)
            void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
            {
                // 共有へ送りたいデータ
                Uri    uri       = this.webView.Source;
                string pageTitle = this.webView.DocumentTitle;

                // - Step 2. Within the OnDataRequested event handler create a ShareSourceData instance and add the data you want to share.
                // ステップ2:WTSのShareSourceDataオブジェクトを作り、共有したいデータをセットする
                var shareSourceData = new ShareSourceData(pageTitle);

                shareSourceData.SetWebLink(uri);

                // - Step 3. Call the SetData extension method before leaving the event handler (i.e. args.Request.SetData(shareSourceData))
                // ステップ3:WTSのSetData拡張メソッドを呼び出す
                args.Request.SetData(shareSourceData);
            }

            // - Step 4. Call the DataTransferManager.ShowShareUI method from your command or handler to start the sharing action
            // ステップ4:ShowShareUI静的メソッドを呼び出すと、共有ポップアップが出る
            DataTransferManager.ShowShareUI();
        }
Ejemplo n.º 3
0
        public static void SetData(this DataRequest dataRequest, ShareSourceData config)
        {
            var deferral = dataRequest.GetDeferral();

            try
            {
                var requestData = dataRequest.Data;
                requestData.Properties.Title = config.Title;
                if (!string.IsNullOrEmpty(config.Description))
                {
                    requestData.Properties.Description = config.Description;
                }

                var storageItems = new List <IStorageItem>();
                foreach (var dataItem in config.Items)
                {
                    switch (dataItem.DataType)
                    {
                    case ShareSourceItemType.Text:
                        requestData.SetText(dataItem.Text);
                        break;

                    case ShareSourceItemType.WebLink:
                        requestData.SetWebLink(dataItem.WebLink);
                        break;

                    case ShareSourceItemType.ApplicationLink:
                        requestData.SetApplicationLink(dataItem.ApplicationLink);
                        break;

                    case ShareSourceItemType.Html:
                        var htmlFormat = HtmlFormatHelper.CreateHtmlFormat(dataItem.Html);
                        requestData.SetHtmlFormat(htmlFormat);
                        break;

                    case ShareSourceItemType.Image:
                        requestData.FillImage(dataItem.Image, storageItems);
                        break;

                    case ShareSourceItemType.StorageItems:
                        requestData.FillStorageItems(dataItem.StorageItems, storageItems);
                        break;

                    case ShareSourceItemType.DeferredContent:
                        requestData.FillDeferredContent(dataItem.DeferredDataFormatId, dataItem.GetDeferredDataAsyncFunc);
                        break;
                    }
                }

                if (storageItems.Any())
                {
                    requestData.SetStorageItems(storageItems);
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
Ejemplo n.º 4
0
        private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            //Share:分享
            ShareSourceData shareSourceData = new ShareSourceData("  ", "  ");//萤火虫发给我的方法

            shareSourceData.SetStorageItems(ApplicationData.Current.TemporaryFolder.GetFilesAsync().AsTask().Result);
            e.Request.SetData(shareSourceData);
        }
Ejemplo n.º 5
0
        private async void MoreOnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            //Share:分享
            ShareSourceData shareSourceData = new ShareSourceData("  ", "  ");//萤火虫发给我的方法

            shareSourceData.SetText(
                "Retouch Photo\r\n" +
                "——form Windows10 UWP Shop\r\n" +
                " https://www.microsoft.com/store/productId/9N2SVF2769GH");
            e.Request.SetData(shareSourceData);
        }