internal ConnectorInfo GetInfo() { ConnectorInfo info = new ConnectorInfo(); info.DesignerItemLeft = DesignerCanvas.GetLeft(this.ParentDesignerItem); info.DesignerItemTop = DesignerCanvas.GetTop(this.ParentDesignerItem); info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight); info.Orientation = this.Orientation; info.Position = this.Position; return(info); }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); DesignerCanvas canvas = GetDesignerCanvas(this); if (canvas != null) { // position relative to DesignerCanvas this.dragStartPoint = new Point?(e.GetPosition(canvas)); e.Handled = true; } }
private void ShowAdorner() { // the ConnectionAdorner is created once for each Connection if (this.connectionAdorner == null) { DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { this.connectionAdorner = new ConnectionAdorner(designer, this); adornerLayer.Add(this.connectionAdorner); } } this.connectionAdorner.Visibility = Visibility.Visible; }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DesignerItem newItem = null; object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DesignerItem(); newItem.Content = content; var ctrl = (newItem.Content as Grid); var tag = ctrl?.Tag; newItem.Name = tag?.ToString(); Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X)); DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectorDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); DropEvent?.Invoke(newItem, new EventArgs()); } e.Handled = true; } }
void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = this.DataContext as DesignerItem; DesignerCanvas designer = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { double minLeft = double.MaxValue; double minTop = double.MaxValue; // we only move DesignerItems var designerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>(); foreach (DesignerItem item in designerItems) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft); minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop); } double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange); double deltaVertical = Math.Max(-minTop, e.VerticalChange); foreach (DesignerItem item in designerItems) { double left = Canvas.GetLeft(item); double top = Canvas.GetTop(item); if (double.IsNaN(left)) { left = 0; } if (double.IsNaN(top)) { top = 0; } Canvas.SetLeft(item, left + deltaHorizontal); Canvas.SetTop(item, top + deltaVertical); } designer.InvalidateMeasure(); e.Handled = true; } }
public ConnectionAdorner(DesignerCanvas designer, Connection connection) : base(designer) { this.designerCanvas = designer; adornerCanvas = new Canvas(); this.visualChildren = new VisualCollection(this); this.visualChildren.Add(adornerCanvas); this.connection = connection; this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged); InitializeDragThumbs(); drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; base.Unloaded += new RoutedEventHandler(ConnectionAdorner_Unloaded); }
void Connection_Unloaded(object sender, RoutedEventArgs e) { // do some housekeeping when Connection is unloaded // remove event handler this.Source = null; this.Sink = null; // remove adorner if (this.connectionAdorner != null) { DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Remove(this.connectionAdorner); this.connectionAdorner = null; } } }
public SelectionService(DesignerCanvas canvas) { this.designerCanvas = canvas; }
void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e) { DesignerItem designerItem = this.DataContext as DesignerItem; DesignerCanvas designer = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas; if (designerItem != null && designer != null && designerItem.IsSelected) { double minLeft, minTop, minDeltaHorizontal, minDeltaVertical; double dragDeltaVertical, dragDeltaHorizontal, scale; IEnumerable <DesignerItem> selectedDesignerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>(); CalculateDragLimits(selectedDesignerItems, out minLeft, out minTop, out minDeltaHorizontal, out minDeltaVertical); foreach (DesignerItem item in selectedDesignerItems) { if (item != null && item.ParentID == Guid.Empty) { switch (base.VerticalAlignment) { case VerticalAlignment.Bottom: dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragBottom(scale, item, designer.SelectionService); break; case VerticalAlignment.Top: double top = Canvas.GetTop(item); dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); scale = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight; DragTop(scale, item, designer.SelectionService); break; default: break; } switch (base.HorizontalAlignment) { case HorizontalAlignment.Left: double left = Canvas.GetLeft(item); dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; DragLeft(scale, item, designer.SelectionService); break; case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal); scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth; DragRight(scale, item, designer.SelectionService); break; default: break; } } } e.Handled = true; } }