protected void Handle_Mouse_Down(MouseButtonEventArgs e) { if (e.ClickCount > 1) return; e.Handled = true; var position = e.GetPosition(this); var elements = VisualTreeHelper.FindElementsInHostCoordinates(position, this); var itemContainer = elements.OfType<WidgetItemContainer>().FirstOrDefault(); if (itemContainer == null) itemContainer = GetWidgets().Where(w => IsInside(w, e)).FirstOrDefault(); if (itemContainer == null) return; Selected_Element = itemContainer; OriginalPosition = e.GetPosition(this); MouseToElementRelativePosition = e.GetPosition(itemContainer); Selected_Element.CaptureMouse(); Bring_To_Front(itemContainer); if (elements.OfType<Grid>().Any(i => i.Name == "resizeAncor")) { Action = EditAction.Resizing; VisualStateManager.GoToState(Selected_Element, "Dragging", true); } else { Action = EditAction.Moving; VisualStateManager.GoToState(Selected_Element, "Dragging", true); } }