From 1d4b23f718cd418a57320e3bf3ebf2f730204024 Mon Sep 17 00:00:00 2001 From: ahopper Date: Sun, 6 Jan 2019 09:14:22 +0000 Subject: [PATCH] fix resize with high dpi on windows --- src/Windows/Avalonia.Win32/WindowImpl.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index fe1c06326f..2b8627a041 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -119,7 +119,7 @@ namespace Avalonia.Win32 } public Size ClientSize - { + { get { UnmanagedMethods.RECT rect; @@ -153,10 +153,14 @@ namespace Avalonia.Win32 public void Resize(Size value) { - var clientRect = ClientSize; - if (value != clientRect) + int requestedClientWidth = (int)(value.Width * Scaling); + int requestedClientHeight = (int)(value.Height * Scaling); + UnmanagedMethods.RECT clientRect; + UnmanagedMethods.GetClientRect(_hwnd, out clientRect); + + // do comparison after scaling to avoid rounding issues + if (requestedClientWidth != clientRect.Width || requestedClientHeight != clientRect.Height) { - value *= Scaling; UnmanagedMethods.RECT windowRect; UnmanagedMethods.GetWindowRect(_hwnd, out windowRect); @@ -165,8 +169,8 @@ namespace Avalonia.Win32 IntPtr.Zero, 0, 0, - (int)(value.Width + (windowRect.Width - clientRect.Width)), - (int)(value.Height + (windowRect.Height - clientRect.Height)), + requestedClientWidth + (windowRect.Width - clientRect.Width), + requestedClientHeight + (windowRect.Height - clientRect.Height), UnmanagedMethods.SetWindowPosFlags.SWP_RESIZE); } }