How to set the location of a WPF window?
Window.Left and Window.Top
var location = myTextBlock.PointToScreen(new Point(0, 0));
window.Left = location.X;
window.Top = location.Y - window.Height;
You need to set the WindowStartupLocation
to Manual
(which is the default however) as well as setting the Top
and Left
property values.
Setting CenterScreen causes a window to be positioned in the center of the screen that contains the mouse cursor.
Setting WindowStartupLocation to CenterOwner causes a window to be positioned in the center of its owner window (see Owner), if specified. The owner window can be either another WPF window or a non-WPF window.
Source