基于 Bill Tarbell 的回答,您可能需要考虑 DPI 缩放:
private Point GetScalingFactor(Window window)
{
var zeroPoint = window.PointToScreen(new Point(0, 0));
var hundredPoint = window.PointToScreen(new Point(100, 100));
return new Point(
100.0 / (hundredPoint.X - zeroPoint.X),
100.0 / (hundredPoint.Y - zeroPoint.Y));
}
private void ShowAtCursor(Window parent, Window toShow)
{
var point = parent.PointToScreen(System.Windows.Input.Mouse.GetPosition(parent));
var scaling = GetScalingFactor(parent);
toShow.Left = point.X * scaling.X;
toShow.Top = point.Y * scaling.Y;
toShow.WindowStartupLocation = WindowStartupLocation.Manual;
toShow.Show();
}