/// <summary> /// Start of the Drag and Drop operation: we set some content and change the DragUI /// depending on the selected options /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void SourceGrid_DragStarting(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.DragStartingEventArgs args) { args.Data.SetText(SourceTextBox.Text); if ((bool)DataPackageRB.IsChecked) { // Standard icon will be used as the DragUIContent args.DragUI.SetContentFromDataPackage(); } else if ((bool)CustomContentRB.IsChecked) { // Generate a bitmap with only the TextBox // We need to take the deferral as the rendering won't be completed synchronously var deferral = args.GetDeferral(); var rtb = new RenderTargetBitmap(); await rtb.RenderAsync(SourceTextBox); var buffer = await rtb.GetPixelsAsync(); var bitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, rtb.PixelWidth, rtb.PixelHeight, BitmapAlphaMode.Premultiplied); args.DragUI.SetContentFromSoftwareBitmap(bitmap); deferral.Complete(); } // else just show the dragged UIElement }
public async void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails; BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId); KeyFob device = new KeyFob(bleDevice); if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected) { if (device.AlertOnDevice && device.HasLinkLossService) { await device.SetAlertLevelCharacteristic(); } } else { if (device.AlertOnPhone) { XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Device {0} is out of range.", device.Name); ToastNotification toast = new ToastNotification(xml); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); } } } finally { deferral.Complete(); } }
private async void GridDrop(object sender, Windows.UI.Xaml.DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { var def = e.GetDeferral(); var items = await e.DataView.GetStorageItemsAsync(); var item = items.FirstOrDefault(); if (item != null) { var originalFile = item as StorageFile; ViewModel.SetNewImage(originalFile); } e.Handled = true; def.Complete(); } }
protected override void OnRun(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral _deferral = taskInstance.GetDeferral(); System.Diagnostics.Debug.WriteLine("OnRun called!"); UpdateTileAsync(_deferral); }
/// <summary> /// Called when the download of a DASH or HLS chunk is requested /// </summary> private async void AdaptiveMediaSource_DownloadRequested(Windows.Media.Streaming.Adaptive.AdaptiveMediaSource sender, Windows.Media.Streaming.Adaptive.AdaptiveMediaSourceDownloadRequestedEventArgs args) { // LogMessage("DownloadRequested for uri: " + args.ResourceUri.ToString()); var deferral = args.GetDeferral(); if (deferral != null) { args.Result.ResourceUri = args.ResourceUri; args.Result.ContentType = args.ResourceType.ToString(); var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter(); filter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache; using (var httpClient = new Windows.Web.Http.HttpClient(filter)) { try { Windows.Web.Http.HttpRequestMessage request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Get, args.Result.ResourceUri); Windows.Web.Http.HttpResponseMessage response = await httpClient.SendRequestAsync(request); // args.Result.ExtendedStatus = (uint)response.StatusCode; if (response.IsSuccessStatusCode) { //args.Result.ExtendedStatus = (uint)response.StatusCode; args.Result.InputStream = await response.Content.ReadAsInputStreamAsync(); } else LogMessage("DownloadRequested for uri: " + args.ResourceUri.ToString() + " error: " + response.StatusCode.ToString()); } catch (Exception e) { LogMessage("DownloadRequested for uri: " + args.ResourceUri.ToString() + " exception: " + e.Message); } // LogMessage("DownloadRequested for uri: " + args.ResourceUri.ToString() + " done"); deferral.Complete(); } } }