开发者

WPF: Bounding Box of Canvas' Children

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜