コード例 #1
0
        public static Point TransformElementToElement(this UIElement @this, Point pt, UIElement target)
        {
            // Find the HwndSource for this element and use it to transform
            // the point up into screen coordinates.
            HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual(@this);

            pt = hwndSource.TransformDescendantToClient(pt, @this);
            pt = hwndSource.TransformClientToScreen(pt);

            // Find the HwndSource for the target element and use it to
            // transform the rectangle from screen coordinates down to the
            // target elemnent.
            HwndSource targetHwndSource = (HwndSource)PresentationSource.FromVisual(target);

            pt = targetHwndSource.TransformScreenToClient(pt);
            pt = targetHwndSource.TransformClientToDescendant(pt, target);

            return(pt);
        }