From c0b13bdc8c21b12793660059f47452ba4b3c0213 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Fri, 12 Apr 2024 01:23:08 +0800 Subject: [PATCH] fix: Fixed the problem that the AvaloniaRider plugin on Windows cannot display the live preview for Avalonia XAML --- src/Native/Windows.cs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index b3027ac0..e936293f 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -73,26 +73,21 @@ namespace SourceGit.Native v.dwOSVersionInfoSize = (uint)Marshal.SizeOf(); if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000)) { - Window.WindowStateProperty.Changed.AddClassHandler((w, e) => - { - if (w.WindowState != WindowState.Maximized) - { - var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 }; - DwmExtendFrameIntoClientArea(w.TryGetPlatformHandle().Handle, ref margins); - } - }); - - Window.LoadedEvent.AddClassHandler((w, e) => - { - if (w.WindowState != WindowState.Maximized) - { - var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 }; - DwmExtendFrameIntoClientArea(w.TryGetPlatformHandle().Handle, ref margins); - } - }); + Window.WindowStateProperty.Changed.AddClassHandler((w, e) => ExtendWindowFrame(w)); + Window.LoadedEvent.AddClassHandler((w, e) => ExtendWindowFrame(w)); } } + private void ExtendWindowFrame(Window w) + { + var platformHandle = w.TryGetPlatformHandle(); + if (platformHandle == null) + return; + + var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 }; + DwmExtendFrameIntoClientArea(platformHandle.Handle, ref margins); + } + public string FindGitExecutable() { var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(