private void ToolBox_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && ToolBoxLastMouseDown.HasValue) { Point mousePos = e.GetPosition(null); Vector diff = ToolBoxLastMouseDown.Value - mousePos; if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) { ToolBoxLastMouseDown = null; var data = new Code.UI.DragDrop.UiElementsListBoxData((Code.AddInUtil.UIElement)(sender as ListBox).SelectedItem); DragDrop.DoDragDrop(sender as ListBox, new DataObject("UiElementsListBoxData", data), DragDropEffects.Move); e.Handled = true; } } }