I have dynamically added paths to a canvas object in the codebehind. How do I get the bounding box of the set of the canvas's children?
I could just iterate through the children, but there has to be a better way:
Rect rect;
foreach (var s in canvas.Children)
{
if (s.Data.Bounds.X > rect.X)
rect开发者_如何学C.X = s.Data.Bounds.X;
...
}
Then once I know the bounding box of the children paths, how do I transform the canvas to center and zoom on the children?
Try using VisualTreeHelper.GetDescendantBounds(). The answer to this question here may also help.
精彩评论