参考方法有以下二种:
方法一:
//_stackPanel为子元素,_grid为父元素
Point point = _stackPanel.TranslatePoint(new Point(0, 0), (UIElement)_grid);
方法二:
//_stackPanel为子元素,_grid为父元素
GeneralTransform generalTransform = _stackPanel.TransformToAncestor(_grid);
Point point = generalTransform.Transform(new Point(0, 0));
用到的NameSpace
using System.Windows;
using System.Windows.Media;
Window window = Window.GetWindow(控件);Point point = 控件.TransformToAncestor(window).Transform(new Point(0, 0));