public static void Share(DataRequest request) { if (ShareInfo != null) { request.Data.Properties.Title = ShareInfo.Title; request.Data.Properties.Description = "PPTV 网络电视"; request.Data.SetText( string.Format(Constants.ShareTips, ShareInfo.Title, PPTVData.Utils.DataCommonUtils.ConvertToWebSite(ShareInfo.Id))); var reference = RandomAccessStreamReference.CreateFromUri(new Uri(ShareInfo.ImageUri)); request.Data.Properties.Thumbnail = reference; var deferral = request.GetDeferral(); request.Data.SetBitmap(reference); deferral.Complete(); } }
protected override bool GetShareContent(DataRequest request) { // Get the user's selection from the WebView. Since this is an asynchronous operation we need to acquire the deferral first. DataRequestDeferral deferral = request.GetDeferral(); // Make sure to always call Complete when done with the deferral. try { var requestDataOperation = ShareWebView.CaptureSelectedContentToDataPackageAsync(); requestDataOperation.Completed += (asyncInfo, status) => { DataPackage requestData = asyncInfo.GetResults(); if ((requestData != null) && (requestData.GetView().AvailableFormats.Count > 0)) { requestData.Properties.Title = "A web snippet for you"; requestData.Properties.Description = "HTML selection from a WebView control"; // The description is optional. requestData.Properties.ContentSourceApplicationLink = ApplicationLink; requestData.Properties.ContentSourceWebLink = new Uri("http://msdn.microsoft.com"); request.Data = requestData; deferral.Complete(); } else { // FailWithDisplayText calls Complete on the deferral. request.FailWithDisplayText("Make a selection in the WebView control and try again."); } }; } catch (Exception) { deferral.Complete(); } // At this point, we haven't populated the data package yet. It's done asynchronously above. return false; }
private async void OnShareRequested(DataRequest request) { var defferal = request.GetDeferral(); await ApplicationData.Current.ClearAsync(ApplicationDataLocality.Temporary); var from = From.Date; var until = Until.Date.AddDays(1).AddMilliseconds(-1); var exportFiles = GetExportFiles(from, until).ToArray(); if (exportFiles.Any()) { request.Data.Properties.Title = "Exported SensorCore files"; request.Data.Properties.Description = "Exported SensorCore files"; request.Data.SetStorageItems(await Task.WhenAll(exportFiles)); } else { request.FailWithDisplayText("Nothing selected to Export."); } defferal.Complete(); }
public SettableDataRequest(DataRequest dataRequest) { Data = dataRequest.Data; _deferral = new Lazy<IDeferral>(() => new DataRequestDeferralAdapter(dataRequest.GetDeferral())); }
private async void ImageSharingHandler(DataPackagePropertySet properties, DataRequest request) { properties.Title = "Compartiendo una imagen desde el Share Charm"; properties.Description = "Se supone que estoy compartiendo la descirpcion con el Share Charm"; // TODO Deferral espera abierta en el sistema // TODO Cuando se esten cargando cosas de manera asincrona debemos llamar el deferrel // TODO para que el sistema espere a la carga de los archivos antes de disparar el proceso completo. var deferral = request.GetDeferral(); // Ctrl + k + s, genera el envoltorio de try try { var thumbFile = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Logo.png"); properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(thumbFile); var imageFile = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Logo.png"); request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile)); } finally { deferral.Complete(); } }
private async void FileSharingHandler(DataPackagePropertySet properties, DataRequest request) { properties.Title = "Compartiendo un conjunto de archivos desde el Share Charm"; properties.Description = "Se supone que estoy compartiendo la descirpcion con el Share Charm"; var deferral = request.GetDeferral(); try { var sampleFile = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\casilleros.xlsx"); // Archivo no existe var sampleFile2 = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Logo.png"); var storageFilesList = new List<IStorageItem>(); storageFilesList.Add(sampleFile); request.Data.SetStorageItems(storageFilesList); } finally { deferral.Complete(); } }