private void HandleDrag(DragEventArgs e, bool drop)
        {
            this.PerformViewModelAction<FunctionEditorDialogViewModel>(editor =>
            {
                var data = e.Data.GetData(typeof(ElementClipboardData)) as IElementClipboardData;

                if (data == null)
                {

                    var factory = e.Data.GetData(typeof(ElementFactory)) as IElementFactory;

                    if (factory == null)
                    {
                        e.Effects = DragDropEffects.None;
                        return;
                    }

                    //Create data from the factory
                    data = new ElementClipboardData(factory);
                }

                //Get the position relative to the design surface
                var position = e.GetPosition(DesignRoot);

                //Find the drop target
                var dropTarget = DesignRoot.GetDropTarget(position, data);

                //Check to see if we can do this
                if (dropTarget == null)
                {
                    if (!editor.Function.CanDrop(data))
                    {
                        e.Effects = DragDropEffects.None;
                        return;
                    }
                }
                else
                {
                    if (!dropTarget.CanDrop(data))
                    {
                        e.Effects = DragDropEffects.None;
                        return;
                    }
                }

                if (((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move) &&
                    ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) &&
                    data.SourceFunctionId.HasValue &&
                    data.SourceFunctionId.Value != editor.Function.Id)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else if ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move)
                {
                    e.Effects = DragDropEffects.Move;
                }
                else if ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy)
                {
                    e.Effects = DragDropEffects.Copy;
                }

                if (drop)
                {
                    if (dropTarget == null)
                    {
                        editor.Function.Drop(data, false);
                    }
                    else
                    {
                        dropTarget.Drop(data);
                    }

                    CurrentDropTarget = null;
                }
                else
                {
                    CurrentDropTarget = dropTarget;
                }

                e.Handled = true;
            });
        }
 private void DesignRoot_OnDragLeave(object sender, DragEventArgs e)
 {
     CurrentDropTarget = null;
 }