I understand that WPF coordinates are different from \"real\" screen coodinates (pixel coordinates) if the computer is not using the default DPI setting. In my program I wan
Does this work if you place it in the code-behind for your Window?
protected override void OnContentRendered(System.EventArgs e)
{
base.OnContentRendered(e);
MoveToLowerRightCorner();
}
private void MoveToLowerRightCorner()
{
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
this.Left = corner.X - this.ActualWidth;
this.Top = corner.Y - this.ActualHeight;
}
Which screen a WPF window is on:
private static Screen GetScreen(Window window)
{
return Screen.FromHandle(new WindowInteropHelper(window).Handle);
}
Open another window in the bottom-left corner of the same screen:
static Point RealPixelsToWpf(Window w, Point p)
{
var t = PresentationSource.FromVisual(w).CompositionTarget.TransformFromDevice;
return t.Transform(p);
}
private static void SetPositionBottomLeftCorner(Window sourceWindow, Window targetWindow)
{
var workingArea = GetScreen(sourceWindow).WorkingArea;
var corner = RealPixelsToWpf(sourceWindow, new Point(workingArea.Left, workingArea.Bottom));
targetWindow.Left = corner.X;
targetWindow.Top = corner.Y - targetWindow.ActualHeight;
}