protected override void Activate(ModelItem item) { designObject = item.GetCurrentValue() as LinkableControl;//获得被点击的控件对象 if (designObject != null) { designCanvas = designObject.Parent as Panel; DesignerView v = DesignerView.FromContext(Context); adorner = new ControlAdorner(designObject); adorner.RenderTransform = new ScaleTransform(v.ZoomLevel, v.ZoomLevel); foreach (var pin in adorner.Children) { pin.MouseLeftButtonDown += new MouseButtonEventHandler(Pin_MouseLeftButtonDown); //按下左键选中hitPin,开始拖动 pin.MouseMove += new MouseEventHandler(Pin_MouseMove); //移动鼠标,开始找寻目标连接节点 } AdornerPanel.SetAdornerHorizontalAlignment(adorner, AdornerHorizontalAlignment.Stretch); AdornerPanel.SetAdornerVerticalAlignment(adorner, AdornerVerticalAlignment.Stretch); _panel.Children.Add(adorner); Adorners.Add(_panel); v.ZoomLevelChanged += (s, e) => { adorner.RenderTransform = new ScaleTransform(v.ZoomLevel, v.ZoomLevel); }; } base.Activate(item); }
protected override void Activate(ModelItem item) { base.Activate(item); CurrentItem = item; View = DesignerView.FromContext(Context); View.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown; }
internal static Vector GetZoomFactor(EditingContext context) { DesignerView designerView = DesignerView.FromContext(context); if (designerView == null) { return(new Vector(1.0, 1.0)); } return(TransformUtil.GetScaleFromTransform(designerView.GetZoomTransform())); }
internal static Transform GetSelectionFrameTransformToDesignerView(EditingContext context, ViewItem view) { DesignerView designerView = DesignerView.FromContext(context); if (designerView == null) { return(Transform.Identity); } return(TransformUtil.GetSelectionFrameTransformToParentVisual(view, (Visual)designerView)); }
internal static DesignerView GetDesignerView(ModelItem item) { EditingContext context = item.Context; DesignerView designerView = (DesignerView)null; if (context != null) { designerView = DesignerView.FromContext(context); } return(designerView); }
internal static CanonicalTransform GetCanonicalTransformToDesignerView(EditingContext context, ViewItem view) { if (view == (ViewItem)null) { throw new ArgumentNullException("view"); } DesignerView designerView = DesignerView.FromContext(context); if (designerView == null) { return(new CanonicalTransform(Transform.Identity)); } return(new CanonicalTransform(TransformUtil.GetTransformToAncestor(view, (Visual)designerView))); }
void Pin_MouseMove(object s, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { isdrag = false; } if (isdrag && hitPin != null && designCanvas != null) { PinAdorner pinAdorner = new PinAdorner(designCanvas, hitPin); pinAdorner.MouseUp += new MouseButtonEventHandler(pinAdorner_MouseUp); DesignerView v = DesignerView.FromContext(Context); double zoom = v.ZoomLevel; pinAdorner.RenderTransform = new ScaleTransform(zoom, zoom); _panel.Children.Add(pinAdorner); e.Handled = true; } }
private static void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e) { if (!(e.PropertyName == BaseAdornerLayout.RenderTransformProperty)) { return; } ModelItem modelItem = sender as ModelItem; if (modelItem == null || !(modelItem.View != (ViewItem)null)) { return; } DesignerView designerView = DesignerView.FromContext(modelItem.Context); if (designerView == null) { return; } designerView.InvalidateArrange(); }
protected override Rect GetBoundingRectangleCore() { if (this._item.Parent == null && this._item != this._item.Root && this._item.Name != null) { ModelItem modelItem = this.ModelService.FromName(this.ModelService.Root, this._item.Name, StringComparison.OrdinalIgnoreCase); if (modelItem != null) { this._item = modelItem; } } PresentationSource presentationSource = PresentationSource.FromVisual((Visual)DesignerView.FromContext(this._item.Context)); if (presentationSource == null || presentationSource.RootVisual == null || !this.ViewItem.IsVisible) { return(new Rect()); } Rect selectionFrameBounds = ElementUtilities.GetSelectionFrameBounds(this.ViewItem); if (selectionFrameBounds.Location == new Point(0.0, 0.0) && selectionFrameBounds.Size == new Size(0.0, 0.0)) { return(new Rect()); } Rect rect1 = new Rect(selectionFrameBounds.Size); Rect rect2 = TransformUtil.GetSelectionFrameTransformToParentVisual(this.ViewItem, presentationSource.RootVisual).TransformBounds(rect1); return(new Rect(presentationSource.RootVisual.PointToScreen(rect2.Location), rect2.Size)); }
internal static Vector GetZoomRounding(EditingContext context) { return(DesignerUtilities.GetZoomRounding(DesignerView.FromContext(context))); }
internal static double GetInvertZoom(EditingContext context) { return(DesignerUtilities.GetInvertZoom(DesignerView.FromContext(context))); }