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(