Example #1
0
        /// <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
        }
Example #2
0
        void HandleDragStarting(UIElement sender, Windows.UI.Xaml.DragStartingEventArgs e)
        {
            SendEventArgs <DragGestureRecognizer>(rec =>
            {
                if (!rec.CanDrag)
                {
                    e.Cancel = true;
                    return;
                }

                var renderer = sender as IVisualElementRenderer;
                var args     = rec.SendDragStarting(renderer?.Element);
                e.Data.Properties["_XFPropertes_DONTUSE"] = args.Data;

                if (!args.Handled && renderer != null)
                {
                    if (renderer.GetNativeElement() is Windows.UI.Xaml.Controls.Image nativeImage &&
                        nativeImage.Source is BitmapImage bi && bi.UriSource != null)
                    {
                        e.Data.SetBitmap(RandomAccessStreamReference.CreateFromUri(bi.UriSource));
                    }
                    else if (!String.IsNullOrWhiteSpace(args.Data.Text))
                    {
                        Uri uri;
                        if (Uri.TryCreate(args.Data.Text, UriKind.Absolute, out uri))
                        {
                            if (args.Data.Text.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                            {
                                e.Data.SetWebLink(uri);
                            }
                            else
                            {
                                e.Data.SetApplicationLink(uri);
                            }
                        }
                        else
                        {
                            e.Data.SetText(args.Data.Text);
                        }
                    }
                }

                e.Cancel            = args.Cancel;
                e.AllowedOperations = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
            });
 /// <summary>
 /// DragStarting is called even if we are starting the Drag Operation ourselved with StartDragAsync
 /// In this sample, we don't really need to handle it
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SourceTextBlock_DragStarting(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.DragStartingEventArgs e)
 {
     e.Data.RequestedOperation = DataPackageOperation.Copy;
     e.Data.SetText(_symbol);
 }
Example #4
0
 private void Draggable_DragStarting(UIElement sender, Windows.UI.Xaml.DragStartingEventArgs args)
 {
     args.Data.SetText("Test Item");
     args.Data.RequestedOperation = DataPackageOperation.Copy;
     Results.Text = "Drag started";
 }