__Description__
There is a bug in the PopupWindowAction class that causes the dialog to not center on its AssociatedObject. In some cases the dialog can appear completely of the screen. It is particularly noticeable on when the system dpi is set to 200% or more on Windows 8.1 systems.
__Steps to reproduce.__
Tested on Windows 8/8.1, though will be reproducible on any windows system.
Make sure the Windows Text size in the Windows Display settings is set to 200% (192dpi).
Open up the Prism InteractivityQuickStart project and run. Click on the buttons to show the dialogs.
Notice the dialogs that appear are not being centered to the owner dialog.
__Cause__
The code in the PopupWindowAction.Invoke method calls
view.PointToScreen(new Point(0, 0));
The PointToScreen mothod returns the true location on the screen in pixels. This value needs to be converted back to WPF's 96.0 Dpi Coords before being used.
__Fix__:
Something like:
Point position = ScreenPointToWpfPoint(view.PointToScreen(new Point(0, 0)));
public Point ScreenPointToWpfPoint(Point location)
{
PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);
if (source != null && source.CompositionTarget != null)
{
double dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
double dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
return new Point(location.X * 96.0 / dpiX, location.Y * 96.0 / dpiY);
}
return location;
}
Also note that the Owner of the new dialog is also not being set, which it should be.
Something like
PresentationSource ps = PresentationSource.FromVisual(this.AssociatedObject);
if (ps != null && ps.RootVisual is Window)
{
wrapperWindow.Owner = ((Window)ps.RootVisual);
}
There is a bug in the PopupWindowAction class that causes the dialog to not center on its AssociatedObject. In some cases the dialog can appear completely of the screen. It is particularly noticeable on when the system dpi is set to 200% or more on Windows 8.1 systems.
__Steps to reproduce.__
Tested on Windows 8/8.1, though will be reproducible on any windows system.
Make sure the Windows Text size in the Windows Display settings is set to 200% (192dpi).
Open up the Prism InteractivityQuickStart project and run. Click on the buttons to show the dialogs.
Notice the dialogs that appear are not being centered to the owner dialog.
__Cause__
The code in the PopupWindowAction.Invoke method calls
view.PointToScreen(new Point(0, 0));
The PointToScreen mothod returns the true location on the screen in pixels. This value needs to be converted back to WPF's 96.0 Dpi Coords before being used.
__Fix__:
Something like:
Point position = ScreenPointToWpfPoint(view.PointToScreen(new Point(0, 0)));
public Point ScreenPointToWpfPoint(Point location)
{
PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);
if (source != null && source.CompositionTarget != null)
{
double dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
double dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
return new Point(location.X * 96.0 / dpiX, location.Y * 96.0 / dpiY);
}
return location;
}
Also note that the Owner of the new dialog is also not being set, which it should be.
Something like
PresentationSource ps = PresentationSource.FromVisual(this.AssociatedObject);
if (ps != null && ps.RootVisual is Window)
{
wrapperWindow.Owner = ((Window)ps.RootVisual);
}