public void StartNativeDrag(CoreDragInfo info)
        => CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.High, async() =>
        {
            try
            {
                var sourceEvent = new NSEvent();
                var source      = new NSDraggingSource2();

                source.DraggingSessionEndedAction =
                    (NSImage image, CGPoint screenPoint, NSDragOperation operation) =>
                {
                    // The drop was completed externally
                    _manager.ProcessDropped(new DragEventSource(info.SourceId, _window));
                    return;
                };

                if (_window.ContentView != null)
                {
                    _window.ContentView.BeginDraggingSession(
                        await DataPackage.CreateNativeDragDropData(info.Data, info.GetPosition(null)),
                        sourceEvent,
                        source);
                }
                else
                {
                    this.Log().Error("Failed to start native Drag and Drop (Window.ContentView is null)");
                }
            }
            catch (Exception e)
            {
                this.Log().Error("Failed to start native Drag and Drop.", e);
            }
        });
        private NSDragOperation OnDraggingEnteredEvent(NSDraggingInfo draggingInfo)
        {
            var source            = new DragEventSource(_fakePointerId, draggingInfo, _window);
            var data              = DataPackage.CreateFromNativeDragDropData(draggingInfo);
            var allowedOperations = DataPackageOperation.Copy;             // Should match with return value
            var info              = new CoreDragInfo(source, data, allowedOperations);

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

            // Note: No need to _manager.ProcessMove, the DragStarted will actually have the same effect

            // To allow the macOS drag to continue, we must assume drop is supported here.
            // This will immediately be updated within the OnDraggingUpdated method.
            return(NSDragOperation.Copy);
        }
Example #3
0
 void IDragDropExtension.StartNativeDrag(CoreDragInfo info)
 {
     // There is no way to programmatically initiate a DragAndDrop in browsers.
     // We instead have to rely on the native drag and drop support.
 }