开发者

WPF: Bounding Box of Canvas' Children

开发者 https://www.devze.com 2023-03-14 10:57 出处:网络
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 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

精彩评论

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