Add this method to the static class:
public static Rect GetAbsolutePlacement(this FrameworkElement element, bool relativeToScreen = false) { var absolutePos = element.PointToScreen(new System.Windows.Point(0, 0)); if (relativeToScreen) { return new Rect(absolutePos.X, absolutePos.Y, element.ActualWidth, element.ActualHeight); } var posMW = Application.Current.MainWindow.PointToScreen(new System.Windows.Point(0, 0)); absolutePos = new System.Windows.Point(absolutePos.X - posMW.X, absolutePos.Y - posMW.Y); return new Rect(absolutePos.X, absolutePos.Y, element.ActualWidth, element.ActualHeight); }
Set relativeToScreen paramater to true to place in the upper left corner of the entire screen or false to place in the upper left corner of the application window.
Andreas Jan 28 '14 at 16:59 2014-01-28 16:59
source share