You can get a Bounding Box for any Visual with TransformToVisual
So, if you have Polygon defined as
<Canvas Name="canvas"> <Polygon Name="polygon" Canvas.Left="12" Canvas.Top="12" Points="0,75 100,0 100,150 0,75" Stroke="Purple" Fill="#9999ff" StrokeThickness="1"/> </Canvas>
You can then add a Border around your bounding box with the following code
private void AddBorderForFrameworkElement(FrameworkElement element) { Rect bounds = element.TransformToVisual(canvas).TransformBounds(new Rect(element.RenderSize)); Border boundingBox = new Border { BorderBrush = Brushes.Red, BorderThickness = new Thickness(1) }; Canvas.SetLeft(boundingBox, bounds.Left); Canvas.SetTop(boundingBox, bounds.Top); boundingBox.Width = bounds.Width; boundingBox.Height = bounds.Height; canvas.Children.Add(boundingBox); }
However, you cannot always get the desired results using this, since the Bounding Box will not always be Bounds for what is actually drawn. If you instead define your Polygon , as shown below, where you start drawing, where x = 100, then the bounding box will be much larger than what is drawn
<Polygon Name="polygon" Canvas.Left="140" Canvas.Top="12" Points="100,75 200,0 200,150 100,75" Stroke="Purple" Fill="#9999ff" StrokeThickness="1"/>

Comparative analysis of boxes
source share