Skip to content

Commit

Permalink
Multi-Monitor DPI scaling breaks dialog sizes (AvaloniaUI#15304)
Browse files Browse the repository at this point in the history
* Multi-Monitor DPI scaling breaks dialog sizes

* move the flag up

* second location
  • Loading branch information
ltetak authored Apr 20, 2024
1 parent 8500621 commit 2ae1628
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Avalonia.Controls/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class Window : WindowBase, IFocusScope, ILayoutRoot
private bool _isExtendedIntoWindowDecorations;
private Thickness _windowDecorationMargin;
private Thickness _offScreenMargin;
private bool _canHandleResized = false;

/// <summary>
/// Defines the <see cref="SizeToContent"/> property.
Expand Down Expand Up @@ -722,6 +723,8 @@ private void ShowCore(Window? owner)
// thus we ought to call it again later to center window correctly if needed, when scaling will be already applied
SetWindowStartupLocation(owner);

_canHandleResized = true;

var initialSize = new Size(
double.IsNaN(Width) ? Math.Max(MinWidth, ClientSize.Width) : Width,
double.IsNaN(Height) ? Math.Max(MinHeight, ClientSize.Height) : Height);
Expand Down Expand Up @@ -800,6 +803,8 @@ public Task<TResult> ShowDialog<TResult>(Window owner)
// determined only by calling this method. But here it will calculate not precise location because scaling may not yet be applied (see i.e. X11Window),
// thus we ought to call it again later to center window correctly if needed, when scaling will be already applied
SetWindowStartupLocation(owner);

_canHandleResized = true;

var initialSize = new Size(
double.IsNaN(Width) ? ClientSize.Width : Width,
Expand Down Expand Up @@ -1036,7 +1041,7 @@ private protected sealed override void HandleClosed()
/// <inheritdoc/>
internal override void HandleResized(Size clientSize, WindowResizeReason reason)
{
if (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height))
if (_canHandleResized && (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height)))
{
var sizeToContent = SizeToContent;

Expand Down

0 comments on commit 2ae1628

Please sign in to comment.