From the MSDN documentation for VisualTreeHelper.GetDescendantBounds():
// Return the bounding rectangle of the parent visual object and all of its descendants.
Rect rectBounds = VisualTreeHelper.GetDescendantBounds(parentVisual);
I get this and it works, but I do not want to include the parent's bounds, the reason is that my parent is a page of an XPS document, and so calling this just returns the page boundaries, which is not what I want. I want the bounding box of everything on the page, i.e. just of the children of the page visual.
// snippet of my code
Visual visual = paginator.GetPage(0).Visual;
Rect contentBounds = VisualTreeHelper.GetDescendantBounds(visual);
// above call returns the page boundaries
// is there a way to get the bounding box of just the children of the page?
The reason I need this is that I'm saving the XPS page to a bitmap and need to include as little white space as possible, to limit the bitmap to only the 'used' area of the page.
Do I need to iterate over all the children of the visual myself and call VisualTreeHelper.GetContentBounds() on each one? I thought there would be a better way than doing this...