示例#1
0
        public void DragStart(DragStartData data)
        {
            if (data.Data == null)
            {
                throw new ArgumentNullException("data");
            }

            DataObject dataObj = data.Data.ToDataObject();

            if (data.ImageBackend != null)
            {
                AdornedWindow           = GetParentWindow();
                AdornedWindow.AllowDrop = true;

                var e = (UIElement)AdornedWindow.Content;

                Adorner = new ImageAdorner(e, data.ImageBackend);

                AdornedLayer = AdornerLayer.GetAdornerLayer(e);
                AdornedLayer.Add(Adorner);

                AdornedWindow.DragOver += AdornedWindowOnDragOver;
            }

            Widget.Dispatcher.BeginInvoke((Action)(() => {
                var effect = DragDrop.DoDragDrop(Widget, dataObj, data.DragAction.ToWpfDropEffect());

                OnDragFinished(this, new DragFinishedEventArgs(effect == DragDropEffects.Move));

                if (Adorner != null)
                {
                    AdornedLayer.Remove(Adorner);
                    AdornedLayer = null;
                    Adorner = null;

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;
                    AdornedWindow = null;
                }
            }));
        }
示例#2
0
        public void DragStart(DragStartData data)
        {
            if (data.Data == null)
                throw new ArgumentNullException ("data");

            DataObject dataObj = data.Data.ToDataObject();

            if (data.ImageBackend != null) {
                AdornedWindow = GetParentWindow ();
                AdornedWindow.AllowDrop = true;

                var e = (UIElement)AdornedWindow.Content;

                Adorner = new ImageAdorner (e, data.ImageBackend);

                AdornedLayer = AdornerLayer.GetAdornerLayer (e);
                AdornedLayer.Add (Adorner);

                AdornedWindow.DragOver += AdornedWindowOnDragOver;
            }

            Widget.Dispatcher.BeginInvoke ((Action)(() => {
                var effect = DragDrop.DoDragDrop (Widget, dataObj, data.DragAction.ToWpfDropEffect ());

                OnDragFinished (this, new DragFinishedEventArgs (effect == DragDropEffects.Move));

                if (Adorner != null) {
                    AdornedLayer.Remove (Adorner);
                    AdornedLayer = null;
                    Adorner = null;

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;
                    AdornedWindow = null;
                }
            }));
        }