Search code examples
wpfbounding-boxbounds

Is it possible to alter the bounds of a WPF element?


I am creating a Path dynamically and I've noticed that the bounding Rect of the shape is far larger than the path itself, like in the picture bellow.

enter image description here

Is it possible to alter those bounds? Unfortunatelly the PathGeometry.Bounds property is read-only.

ps: If it helps, I am interested in narrowing the bounds so I can set RenderTransformOrigin of the path to new Point(0.5,0.5) to Rotate (RotateTransform) that path around itself.

Creation of PathFigure

I am defining 4 points and then I create three LineSegments and the ArcSegment. I've created a Circle struct to use as a guide to calculate those points.

private PathFigure CreateFigure()
        {
            var lineAB = new LineSegment(pointB, true);
            var arcBC = new ArcSegment(pointC, new Size(_outerCircle.Radius, _outerCircle.Radius), 0, false, SweepDirection.Clockwise, true);
            var lineCD = new LineSegment(pointD, true);

            return new PathFigure(pointA, new List<PathSegment> { lineAB, arcBC, lineCD }, true);
        }

Solution

  • Since it's impossible to alter the bounds after they're defined, adding the Path as a child to a Grid or a Border and setting Path.Stretch="Fill" would force the bounds to be filled by the path during the layout pass.