Example #1
0
        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 = WindowStateManager.Default.GetActiveWindowHandle(true);
            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.Current.Name;

                dataTransferManager.DataRequested -= ShareTextHandler;
            }
        }
Example #2
0
        Task PlatformRequestAsync(ShareTextRequest request)
        {
            var hwnd = WindowStateManager.Default.GetActiveWindowHandle(true);
            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.Current.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);
        }