Example #1
0
        static async Task PlatformRequestAsync(ShareMultipleFilesRequest request)
        {
            var storageFiles = new List <IStorageFile>();

            foreach (var file in request.Files)
            {
                storageFiles.Add(file.File ?? await StorageFile.GetFileFromPathAsync(file.FullPath));
            }

            var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(Platform.CurrentWindow);
            var dataTransferManager = DataTransferManagerHelper.GetDataTransferManager(hwnd);

            dataTransferManager.DataRequested += ShareTextHandler;

            DataTransferManagerHelper.ShowShare(hwnd);

            void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)
            {
                var newRequest = e.Request;

                newRequest.Data.SetStorageItems(storageFiles.ToArray());
                newRequest.Data.Properties.Title = request.Title ?? AppInfo.Name;

                dataTransferManager.DataRequested -= ShareTextHandler;
            }
        }
Example #2
0
        static Task PlatformRequestAsync(ShareTextRequest request)
        {
            var hwnd = Platform.CurrentWindowHandle;
            var dataTransferManager = DataTransferManagerHelper.GetDataTransferManager(hwnd);

            dataTransferManager.DataRequested += ShareTextHandler;

            DataTransferManagerHelper.ShowShare(hwnd);

            void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)
            {
                var newRequest = e.Request;

                newRequest.Data.Properties.Title = request.Title ?? AppInfo.Name;

                if (!string.IsNullOrWhiteSpace(request.Text))
                {
                    newRequest.Data.SetText(request.Text);
                }

                if (!string.IsNullOrWhiteSpace(request.Uri))
                {
                    newRequest.Data.SetWebLink(new Uri(request.Uri));
                }

                dataTransferManager.DataRequested -= ShareTextHandler;
            }

            return(Task.CompletedTask);
        }