Exemple #1
0
        public void BeginDragAndDrop(CoreDragInfo info, ICoreDropOperationTarget?target = null)
        {
            if (
#if __WASM__
                _window.Dispatcher.IsThreadingSupported&&
#endif
                !_window.Dispatcher.HasThreadAccess)
            {
                _window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => BeginDragAndDrop(info, target));
                return;
            }

            if (!AreConcurrentOperationsEnabled)
            {
                foreach (var pending in _dragOperations.ToArray())
                {
                    pending.Abort();
                }
            }

            RegisterWindowHandlers();

            var op = new DragOperation(_window, _hostExtension, info, target);

            _dragOperations.Add(op);
            info.RegisterCompletedCallback(_ => _dragOperations.Remove(op));
        }
Exemple #2
0
        internal DropCompletedEventArgs(UIElement originalSource, CoreDragInfo info, DataPackageOperation result)
            : base(originalSource)
        {
            Info       = info;
            DropResult = result;

            CanBubbleNatively = false;
        }
Exemple #3
0
        public DragOperation(Window window, IDragDropExtension?extension, CoreDragInfo info, ICoreDropOperationTarget?target = null)
        {
            _extension = extension;
            Info       = info;

            _target       = target ?? new DropUITarget(window);       // The DropUITarget must be re-created for each drag operation! (Caching of the drag ui-override)
            _view         = new DragView(info.DragUI as DragUI);
            _viewHandle   = window.OpenDragAndDrop(_view);
            _viewOverride = new CoreDragUIOverride();             // UWP does re-use the same instance for each update on _target
        }
        private void OnHostDragEnter(object sender, DragEventArgs e)
        {
            var src  = new DragEventSource(_fakePointerId, e);
            var data = ToDataPackage(e.Data);
            var allowedOperations = ToDataPackageOperation(e.AllowedEffects);
            var info = new CoreDragInfo(src, data.GetView(), allowedOperations);

            CoreDragDropManager.GetForCurrentView()?.DragStarted(info);

            // Note: No needs to _manager.ProcessMove, the DragStarted will actually have the same effect
        }
Exemple #5
0
 public IAsyncOperation <DataPackageOperation> DropAsync(CoreDragInfo dragInfo)
 {
     Debug.WriteLine("DropAsync");
     if (dragInfo.Data.Contains("FileNameW"))
     {
         var fileName = dragInfo.Data.GetTextAsync("FileNameW").AsTask <string>().Result;
         FileNameText.Text = fileName;
         Debug.WriteLine("FileName=" + fileName);
     }
     return(Task.Run <DataPackageOperation>(() => DataPackageOperation.Copy).AsAsyncOperation <DataPackageOperation>());
 }
Exemple #6
0
        internal DragEventArgs(
            UIElement originalSource,
            CoreDragInfo info,
            DragUIOverride uiOverride)
            : base(originalSource)
        {
            CanBubbleNatively = false;

            _info = info;

            DragUIOverride = uiOverride;
        }
        public void StartNativeDrag(CoreDragInfo info)
        => WpfHost.Current.Dispatcher.InvokeAsync(async() =>
        {
            try
            {
                var data    = await ToDataObject(info.Data, CancellationToken.None);
                var effects = ToDropEffects(info.AllowedOperations);

                DragDrop.DoDragDrop(WpfHost.Current, data, effects);
            }
            catch (Exception e)
            {
                this.Log().Error("Failed to start native Drag and Drop.", e);
            }
        });
Exemple #8
0
 public IAsyncAction LeaveAsync(CoreDragInfo dragInfo)
 {
     Debug.WriteLine("LeaveAsync");
     return(Task.Run(() => { return; }).AsAsyncAction());
 }
Exemple #9
0
 public IAsyncOperation <DataPackageOperation> OverAsync(CoreDragInfo dragInfo, CoreDragUIOverride dragUIOverride)
 {
     Debug.WriteLine("OverAsync");
     return(Task.Run <DataPackageOperation>(() => DataPackageOperation.Copy).AsAsyncOperation <DataPackageOperation>());
 }