private void RemoveAdorner() { if (this.adorner != null) { AdornerLayer.GetAdornerLayer(this.sourceBox).Remove(adorner); this.adorner = null; } }
private void ShowAdorner(DragEventArgs e) { if (adorner == null) { adorner = new DragAdorner(this.sourceItem, this.startPoint); AdornerLayer.GetAdornerLayer(this.sourceBox).Add(adorner); } adorner.UpdatePosition(e.GetPosition(this.topWindow)); }
private void StartDragInProcAdorner(MouseEventArgs e) { // Let's define our DragScope .. In this case it is every thing inside our main window .. DragScope = Program.MainWindow.Content as FrameworkElement; Debug.Assert(DragScope != null); // We enable Drag & Drop in our scope ... We are not implementing Drop, so it is OK, but this allows us to get DragOver bool previousDrop = DragScope != null && DragScope.AllowDrop; if (DragScope != null) DragScope.AllowDrop = true; // Let's wire our usual events.. // GiveFeedback just tells it to use no standard cursors.. GiveFeedbackEventHandler feedbackhandler = DragSourceGiveFeedback; GiveFeedback += feedbackhandler; // The DragOver event ... DragEventHandler draghandler = Window1DragOver; DragScope.PreviewDragOver += draghandler; // Drag Leave is optional, but write up explains why I like it .. DragEventHandler dragleavehandler = DragScopeDragLeave; DragScope.DragLeave += dragleavehandler; // QueryContinue Drag goes with drag leave... QueryContinueDragEventHandler queryhandler = DragScopeQueryContinueDrag; DragScope.QueryContinueDrag += queryhandler; //Here we create our adorner.. _adorner = new DragAdorner(DragScope, this, true, 0.5); _layer = AdornerLayer.GetAdornerLayer(DragScope); _layer.Add(_adorner); IsDragging = true; _dragHasLeftScope = false; //Finally lets drag drop //var data = new DataObject(DataFormats.Text, "abcd"); //DragDropEffects de = DragDrop.DoDragDrop(this, data, DragDropEffects.Move); // Clean up our mess :) DragScope.AllowDrop = previousDrop; AdornerLayer.GetAdornerLayer(DragScope).Remove(_adorner); _adorner = null; GiveFeedback -= feedbackhandler; DragScope.DragLeave -= dragleavehandler; DragScope.QueryContinueDrag -= queryhandler; DragScope.PreviewDragOver -= draghandler; IsDragging = false; }