Browse Source

Fall back to CenterScreen when owner is minimized.

When showing a child window with `WindowStartupLocation = CenterOwner` to a minimized owner window, we were displaying the child in an invalid position. Use the WPF behavior of falling back to `CenterScreen` in this situation.

Fixes #7582
pull/7730/head
Steven Kirk 4 years ago
parent
commit
77d80faec2
  1. 15
      src/Avalonia.Controls/Window.cs

15
src/Avalonia.Controls/Window.cs

@ -858,6 +858,17 @@ namespace Avalonia.Controls
private void SetWindowStartupLocation(IWindowBaseImpl? owner = null)
{
var startupLocation = WindowStartupLocation;
if (startupLocation == WindowStartupLocation.CenterOwner &&
Owner is Window ownerWindow &&
ownerWindow.WindowState == WindowState.Minimized)
{
// If startup location is CenterOwner, but owner is minimized then fall back
// to CenterScreen. This behavior is consistent with WPF.
startupLocation = WindowStartupLocation.CenterScreen;
}
var scaling = owner?.DesktopScaling ?? PlatformImpl?.DesktopScaling ?? 1;
// TODO: We really need non-client size here.
@ -865,7 +876,7 @@ namespace Avalonia.Controls
PixelPoint.Origin,
PixelSize.FromSize(ClientSize, scaling));
if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
if (startupLocation == WindowStartupLocation.CenterScreen)
{
var screen = Screens.ScreenFromPoint(owner?.Position ?? Position);
@ -874,7 +885,7 @@ namespace Avalonia.Controls
Position = screen.WorkingArea.CenterRect(rect).Position;
}
}
else if (WindowStartupLocation == WindowStartupLocation.CenterOwner)
else if (startupLocation == WindowStartupLocation.CenterOwner)
{
if (owner != null)
{

Loading…
Cancel
Save