Пример #1
0
        void StartDrag(MouseEventArgs args)
        {
            IDataObject data = null;
            UIElement dragelement = null;

            // ADD THE DATA
            if (_callback != null)
            {
                DragDataWrapper dw = new DragDataWrapper();

                data = new DataObject(typeof(DragDataWrapper).ToString(), dw);

                if ((_callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0)
                    _callback.AppendData(ref data, args);

                if ((_callback.SupportedActions & DragDropProviderActions.Data) != 0)
                    dw.Data = _callback.GetData();

                if ((_callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                    dragelement = _callback.GetVisual(args);
                else
                    dragelement = args.OriginalSource as UIElement;

                dw.Source = _dragSource;
                dw.Shim = _callback;
            }
            else
            {

                dragelement = args.OriginalSource as UIElement;
                data = new DataObject(typeof(UIElement).ToString(), dragelement);
            }

            // mwa changed from:
            // if (dragelement == null || data == null || dragelement == this._dragSource)
            if (dragelement == null || data == null)
                return;

            DragEventHandler dragOver = null;
            DragEventHandler dragLeave = null;
            QueryContinueDragEventHandler queryContinue = null;
            GiveFeedbackEventHandler giveFeedback = null;

            DragDropEffects effects = GetDragDropEffects();
            DragDropEffects resultEffects;

            // Inprocess Drag  ...
            if (DragScope != null)
            {
                bool previousAllowDrop = DragScope.AllowDrop;
                _adorner = new DragAdorner(DragScope, (UIElement)dragelement, true, Opacity);
                _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual);
                _layer.Add(_adorner);

                if (DragScope != _dragSource)
                {
                    DragScope.AllowDrop = true;
                    System.Windows.DragDrop.AddPreviewDragOverHandler((DependencyObject)DragScope, dragOver = new DragEventHandler(DragScope_DragOver));
                    System.Windows.DragDrop.AddPreviewDragLeaveHandler(DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave));
                    System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag));
                }

                try
                {
                    IsDragging = true;
                    this._mouseLeftScope = false;
                    resultEffects = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects);
                    DragFinished(resultEffects);
                }
                catch
                {
                }

                if (DragScope != _dragSource)
                {
                    DragScope.AllowDrop = previousAllowDrop;
                    System.Windows.DragDrop.RemovePreviewDragOverHandler(DragScope, dragOver);
                    System.Windows.DragDrop.RemovePreviewDragLeaveHandler(DragScope, dragLeave);
                    System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, queryContinue);
                }
            }
            else
            {

                System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag));
                System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, giveFeedback = new GiveFeedbackEventHandler(onGiveFeedback));
                IsDragging = true;
                CreateDragDropWindow(dragelement);
                this._dragdropWindow.Show();
                try
                {
                    resultEffects = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects);
                }
                finally { }
                DestroyDragDropWindow();
                System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, onQueryContinueDrag);
                System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, onGiveFeedback);
                IsDragging = false;
                DragFinished(resultEffects);
            }
        }
Пример #2
0
        void StartDrag(MouseEventArgs args)
        {
            IDataObject data        = null;
            UIElement   dragelement = null;


            // ADD THE DATA
            if (_callback != null)
            {
                DragDataWrapper dw = new DragDataWrapper();

                data = new DataObject(typeof(DragDataWrapper).ToString(), dw);

                if ((_callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0)
                {
                    _callback.AppendData(ref data, args);
                }

                if ((_callback.SupportedActions & DragDropProviderActions.Data) != 0)
                {
                    dw.Data = _callback.GetData();
                }

                if ((_callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    dragelement = _callback.GetVisual(args);
                }
                else
                {
                    dragelement = args.OriginalSource as UIElement;
                }

                dw.Source = _dragSource;
                dw.Shim   = _callback;
            }
            else
            {
                dragelement = args.OriginalSource as UIElement;
                data        = new DataObject(typeof(UIElement).ToString(), dragelement);
            }


            // mwa changed from:
            // if (dragelement == null || data == null || dragelement == this._dragSource)
            if (dragelement == null || data == null)
            {
                return;
            }

            DragEventHandler dragOver  = null;
            DragEventHandler dragLeave = null;
            QueryContinueDragEventHandler queryContinue = null;
            GiveFeedbackEventHandler      giveFeedback  = null;


            DragDropEffects effects = GetDragDropEffects();
            DragDropEffects resultEffects;

            // Inprocess Drag  ...
            if (DragScope != null)
            {
                bool previousAllowDrop = DragScope.AllowDrop;
                _adorner = new DragAdorner(DragScope, (UIElement)dragelement, true, Opacity);
                _layer   = AdornerLayer.GetAdornerLayer(DragScope as Visual);
                _layer.Add(_adorner);

                if (DragScope != _dragSource)
                {
                    DragScope.AllowDrop = true;
                    System.Windows.DragDrop.AddPreviewDragOverHandler((DependencyObject)DragScope, dragOver = new DragEventHandler(DragScope_DragOver));
                    System.Windows.DragDrop.AddPreviewDragLeaveHandler(DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave));
                    System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag));
                }

                try
                {
                    IsDragging           = true;
                    this._mouseLeftScope = false;
                    resultEffects        = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects);
                    DragFinished(resultEffects);
                }
                catch
                {
                }

                if (DragScope != _dragSource)
                {
                    DragScope.AllowDrop = previousAllowDrop;
                    System.Windows.DragDrop.RemovePreviewDragOverHandler(DragScope, dragOver);
                    System.Windows.DragDrop.RemovePreviewDragLeaveHandler(DragScope, dragLeave);
                    System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, queryContinue);
                }
            }
            else
            {
                System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag));
                System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, giveFeedback = new GiveFeedbackEventHandler(onGiveFeedback));
                IsDragging = true;
                CreateDragDropWindow(dragelement);
                this._dragdropWindow.Show();
                try
                {
                    resultEffects = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects);
                }
                finally { }
                DestroyDragDropWindow();
                System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, onQueryContinueDrag);
                System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, onGiveFeedback);
                IsDragging = false;
                DragFinished(resultEffects);
            }
        }
Пример #3
0
        protected void DragFinished(DragDropEffects ret)
        {
            System.Windows.Input.Mouse.Capture(null);
            if (IsDragging)
            {
                if (DragScope != null)
                {
                    AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner);
                    _adorner = null;
                }
                else
                {
                    DestroyDragDropWindow();
                }

            }
            IsDragging = false;
        }