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 Transform GetSelectionFrameTransformToParentVisual(DependencyObject view, Visual ancestorView) { FrameworkElement frameworkElement = view as FrameworkElement; if (frameworkElement != null && (frameworkElement.LayoutTransform == null || frameworkElement.LayoutTransform == Transform.Identity)) { Transform toImmediateParent = TransformUtil.GetTransformToImmediateParent(view); DependencyObject parent = VisualTreeHelper.GetParent(view); Rect selectionFrameBounds = ElementUtilities.GetSelectionFrameBounds(view); Vector vector = new Vector(selectionFrameBounds.X, selectionFrameBounds.Y); Matrix matrix = toImmediateParent.Value; matrix.Translate(vector.X, vector.Y); if (parent != ancestorView) { Transform transformToAncestor = TransformUtil.GetTransformToAncestor(parent, ancestorView); return((Transform) new MatrixTransform(matrix * transformToAncestor.Value)); } } return(TransformUtil.GetTransformToAncestor(view, ancestorView)); }
internal override Rect GetBoundingBox(ViewItem element) { return(ElementUtilities.GetSelectionFrameBounds(element)); }