// Helper function to calculate an element's rectangle in root-relative coordinates.
 public static Rect GetElementRect(Windows.UI.Xaml.FrameworkElement element)
 {
     Windows.UI.Xaml.Media.GeneralTransform transform = element.TransformToVisual(null);
     Point point = transform.TransformPoint(new Point());
     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
 }