private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e) { var designerItem = this.DataContext as Control; if (designerItem != null) { MenuPageEditorViewModel menuPageEditor = designerItem.DataContext as MenuPageEditorViewModel; if (_isMousePressMove == false) { menuPageEditor.CreateNewPropertyMementos(); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectLeft", menuPageEditor.EditorRectLeft, menuPageEditor.EditorRectLeft)); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectTop", menuPageEditor.EditorRectTop, menuPageEditor.EditorRectTop)); _isMousePressMove = true; } double left = Canvas.GetLeft(designerItem); double top = Canvas.GetTop(designerItem); double xOffset = e.HorizontalChange; double yOffset = e.VerticalChange; Rect doundingRect = new Rect(menuPageEditor.EditorRectLeft, menuPageEditor.EditorRectTop, menuPageEditor.EditorRectWidth, menuPageEditor.EditorRectHeight); Snap(doundingRect, ref xOffset, ref yOffset); Canvas.SetLeft(designerItem, left + xOffset); Canvas.SetTop(designerItem, top + yOffset); } }
private void MoveThumb_DragCompleted(object sender, DragCompletedEventArgs e) { var designerItem = this.DataContext as Control; if (designerItem != null && _isMousePressMove) { MenuPageEditorViewModel menuPageEditor = designerItem.DataContext as MenuPageEditorViewModel; menuPageEditor.PropertyMementos.SetPropertyNewValue("Raw_EditorRectLeft", menuPageEditor.EditorRectLeft); menuPageEditor.PropertyMementos.SetPropertyNewValue("Raw_EditorRectTop", menuPageEditor.EditorRectTop); PropertyChangeCommand cmd = new PropertyChangeCommand(menuPageEditor, menuPageEditor.PropertyMementos); (_page as ISupportUndo).UndoManager.Push(cmd); } }
private void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { Control designerItem = this.DataContext as Control; if (designerItem != null) { if (_isMousePressMove == false) { MenuPageEditorViewModel menuPageEditor = designerItem.DataContext as MenuPageEditorViewModel; menuPageEditor.CreateNewPropertyMementos(); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectLeft", menuPageEditor.EditorRectLeft, menuPageEditor.EditorRectLeft)); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectTop", menuPageEditor.EditorRectTop, menuPageEditor.EditorRectTop)); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectWidth", menuPageEditor.EditorRectWidth, menuPageEditor.EditorRectWidth)); menuPageEditor.PropertyMementos.AddPropertyMemento(new PropertyMemento("Raw_EditorRectHeight", menuPageEditor.EditorRectHeight, menuPageEditor.EditorRectHeight)); _isMousePressMove = true; } double deltaVertical, deltaHorizontal; switch (VerticalAlignment) { case VerticalAlignment.Bottom: deltaVertical = e.VerticalChange; double snapBottom = Canvas.GetTop(designerItem) + (designerItem.ActualHeight + e.VerticalChange); double snapBottomDelta = CalculateSnapChangeDelta(snapBottom, Service.Document.Orientation.Vertical); deltaVertical += snapBottomDelta; deltaVertical = Math.Min(-deltaVertical, designerItem.ActualHeight - designerItem.MinHeight); designerItem.Height -= deltaVertical; break; case VerticalAlignment.Top: deltaVertical = Math.Min(e.VerticalChange, designerItem.ActualHeight - designerItem.MinHeight); double snapTop = Canvas.GetTop(designerItem) + deltaVertical; double snapTopDelta = CalculateSnapChangeDelta(snapTop, Service.Document.Orientation.Vertical); deltaVertical += snapTopDelta; Canvas.SetTop(designerItem, Canvas.GetTop(designerItem) + deltaVertical); designerItem.Height -= deltaVertical; break; default: break; } switch (HorizontalAlignment) { case HorizontalAlignment.Left: deltaHorizontal = Math.Min(e.HorizontalChange, designerItem.ActualWidth - designerItem.MinWidth); double snapLeft = Canvas.GetLeft(designerItem) + deltaHorizontal; double snapLeftDelta = CalculateSnapChangeDelta(snapLeft, Service.Document.Orientation.Vertical); deltaHorizontal += snapLeftDelta; Canvas.SetLeft(designerItem, Canvas.GetLeft(designerItem) + deltaHorizontal); designerItem.Width -= deltaHorizontal; break; case HorizontalAlignment.Right: deltaHorizontal = e.HorizontalChange; double snapRight = Canvas.GetLeft(designerItem) + (designerItem.ActualWidth + e.HorizontalChange); double snapRightDelta = CalculateSnapChangeDelta(snapRight, Service.Document.Orientation.Vertical); deltaHorizontal += snapRightDelta; deltaHorizontal = Math.Min(-deltaHorizontal, designerItem.ActualWidth - designerItem.MinWidth); designerItem.Width -= deltaHorizontal; break; default: break; } } e.Handled = true; }