private void ResizeSelectedShapes_Executed(DragDeltaThumbEvent e) { if (this.Parent != null) { this.Parent.ResizeSelectedShapes(e); } }
public void ResizeThumb_DragDelta(object sender, DragDeltaThumbEvent e) { if (this.mResizeSelectedShapes != null) { // Call the bound (ShapeSizeViewModel) to implement this change via (XAML) command binding if (this.mResizeSelectedShapes.CanExecute(null)) { this.mResizeSelectedShapes.Execute(e); } } }
/// <summary> /// The resize shape function resizes all currently selected /// shapes in accordance to the delta contained in the supplied /// <paramref name="e"/> parameter. /// /// Method is based on resize method in /// http://www.codeproject.com/Articles/23871/WPF-Diagram-Designer-Part-3 /// </summary> /// <param name="e"></param> void IShapeParent.ResizeSelectedShapes(DragDeltaThumbEvent e) { if (SelectedItem.Shapes.Count == 0) { return; } double minLeft = double.MaxValue; double minTop = double.MaxValue; double minDeltaHorizontal = double.MaxValue; double minDeltaVertical = double.MaxValue; double dragDeltaVertical, dragDeltaHorizontal; // filter for those items that contain a height property and // find the min of their min (Height, Width) properties foreach (var item in this.SelectedItem.Shapes) { ShapeSizeViewModelBase shape = item as ShapeSizeViewModelBase; if (shape == null) // filter for those items that have a height or width { continue; } minLeft = Math.Min(shape.Left, minLeft); minTop = Math.Min(shape.Top, minTop); minDeltaVertical = Math.Min(minDeltaVertical, shape.Height - shape.MinHeight); minDeltaHorizontal = Math.Min(minDeltaHorizontal, shape.Width - shape.MinWidth); } // Resize currently selected items with regard to min height and width determined before foreach (var item in this.SelectedItem.Shapes) { ShapeSizeViewModelBase shape = item as ShapeSizeViewModelBase; if (shape == null) // filter for those items that have a height or width { continue; } switch (e.VerticalAlignment) { // Changing an element at its bottom changes the its height only case VerticalAlignment.Bottom: dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical); shape.Height = shape.Height - dragDeltaVertical; break; // Changing an element at its top changes the Y position and the height case VerticalAlignment.Top: dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); shape.Top = shape.Top + dragDeltaVertical; shape.Height = shape.Height - dragDeltaVertical; break; } switch (e.HorizontalAlignment) { // Changing an element at its left side changes the x position and its width case HorizontalAlignment.Left: dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); shape.Left = shape.Left + dragDeltaHorizontal; shape.Width = shape.Width - dragDeltaHorizontal; break; // Changing an element at its right side changes the its width only case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal); shape.Width = shape.Width - dragDeltaHorizontal; break; } } }