public DragBehavior(UIElement DraggableArea, UIElement DraggableElement, UIElement DragContainer) { var drag = new { X = 0.0, Y = 0.0 }.ToDefault(); DraggableArea.MouseLeftButtonDown += (sender, args) => { if (DragStart != null) DragStart(); var p = args.GetPosition(DraggableElement); drag = new { p.X, p.Y }; }; DragContainer.MouseMove += (sender, args) => { if (drag == null) return; var p = args.GetPosition(DragContainer); var q = new { X = SnapX(p.X - drag.X), Y = SnapY(p.Y - drag.Y) }; DraggableElement.MoveTo(q.X, q.Y); }; DragContainer.MouseLeftButtonUp += (sender, args) => { if (drag == null) return; if (DragStop != null) DragStop(); drag = null; }; }