I consider this a pretty simple request, but I can't seem to find a conclusive answer in my searches. How can I determine the bounds of a particular visual element in my window, relative to some other parent element?
I've tried using LayoutInformation.GetLayoutSlot
but this just seems to return a Rect
at 0,0 and doesn't reflect the actual location of the element.
What I'm trying to do is take a "screenshot" of a window using RenderTargetBitmap
and then crop it to a particular element, but I can't get the element's bounds to know what to crop the bitmap to!
GetLayoutSlot
gets the space that's allocated in the layout for the element, but the actual element size could be different if it has an explicit width/height and/or a transform. To get the "true" size rect, tryelement.RenderTransform.TransformBounds(new Rect(element.RenderSize))
. – Dethrone