2012-08-28 30 views
8

找不到在Metro风格应用程序中找到UIElement的绝对位置的方法。有人知道解决方案吗?WinRT中UIElement的绝对坐标

(背景:我想旁边的按钮来显示一个弹出叫它)

回答

21

这应该工作...

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    var button = sender as Button; 
    var ttv = button.TransformToVisual(Window.Current.Content); 
    Point screenCoords = ttv.TransformPoint(new Point(0, 0)); 
} 
+0

烨,工作。非常感谢! – snuk182

+0

有点不明智,但它是有道理的,我猜。感谢您的解决方案。 –