private void DistributeVertical_Executed(object sender, RoutedEventArgs e) { var selectedItems = from item in SelectionService.CurrentSelection.OfType <DesignerItem>() where item.ParentID == Guid.Empty let itemTop = Canvas.GetTop(item) orderby itemTop select item; if (selectedItems.Count() > 1) { double top = Double.MaxValue; double bottom = Double.MinValue; double sumHeight = 0; foreach (DesignerItem item in selectedItems) { top = Math.Min(top, Canvas.GetTop(item)); bottom = Math.Max(bottom, Canvas.GetTop(item) + item.Height); sumHeight += item.Height; } double distance = Math.Max(0, (bottom - top - sumHeight) / (selectedItems.Count() - 1)); double offset = Canvas.GetTop(selectedItems.First()); foreach (DesignerItem item in selectedItems) { double delta = offset - Canvas.GetTop(item); foreach (DesignerItem di in SelectionService.GetGroupMembers(item)) { Canvas.SetTop(di, Canvas.GetTop(di) + delta); } offset = offset + item.Height + distance; } } }
private void DistributeHorizontal_Executed(object sender, RoutedEventArgs e) { var selectedItems = from item in SelectionService.CurrentSelection.OfType <DesignerItem>() where item.ParentID == Guid.Empty let itemLeft = Canvas.GetLeft(item) orderby itemLeft select item; if (selectedItems.Count() > 1) { double left = Double.MaxValue; double right = Double.MinValue; double sumWidth = 0; foreach (DesignerItem item in selectedItems) { left = Math.Min(left, Canvas.GetLeft(item)); right = Math.Max(right, Canvas.GetLeft(item) + item.Width); sumWidth += item.Width; } double distance = Math.Max(0, (right - left - sumWidth) / (selectedItems.Count() - 1)); double offset = Canvas.GetLeft(selectedItems.First()); foreach (DesignerItem item in selectedItems) { double delta = offset - Canvas.GetLeft(item); foreach (DesignerItem di in SelectionService.GetGroupMembers(item)) { Canvas.SetLeft(di, Canvas.GetLeft(di) + delta); } offset = offset + item.Width + distance; } } }
private void AlignRight_Executed(object sender, RoutedEventArgs e) { var selectedItems = from item in SelectionService.CurrentSelection.OfType <DesignerItem>() where item.ParentID == Guid.Empty select item; if (selectedItems.Count() > 1) { double right = Canvas.GetLeft(selectedItems.First()) + selectedItems.First().Width; foreach (DesignerItem item in selectedItems) { double delta = right - (Canvas.GetLeft(item) + item.Width); foreach (DesignerItem di in SelectionService.GetGroupMembers(item)) { Canvas.SetLeft(di, Canvas.GetLeft(di) + delta); } } } }
private void AlignBottom_Executed(object sender, RoutedEventArgs e) { var selectedItems = from item in SelectionService.CurrentSelection.OfType <DesignerItem>() where item.ParentID == Guid.Empty select item; if (selectedItems.Count() > 1) { double bottom = Canvas.GetTop(selectedItems.First()) + selectedItems.First().Height; foreach (DesignerItem item in selectedItems) { double delta = bottom - (Canvas.GetTop(item) + item.Height); foreach (DesignerItem di in SelectionService.GetGroupMembers(item)) { Canvas.SetTop(di, Canvas.GetTop(di) + delta); } } } }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down) { object originalSource = e.OriginalSource; if (originalSource is DesignerItem) { var movementViewModel = new MovementViewModel(); e.Handled = true; var item = originalSource as DesignerItem; if (item.ParentID != Guid.Empty) { var groupMembers = selectionService.GetGroupMembers(item).OfType <DesignerItem>(); bool leftConstrained = groupMembers.Any(designerItem => Canvas.GetLeft(designerItem) == 0); bool topConstrained = groupMembers.Any(designerItem => Canvas.GetTop(designerItem) == 0); if (e.Key == Key.Left && leftConstrained || e.Key == Key.Up && topConstrained) { return; } foreach (DesignerItem designerItem in groupMembers) { movementViewModel.HandleKeyDown(e, designerItem); } } else { movementViewModel.HandleKeyDown(e, item); } } } }