From e4162eeeb6919d39bef0e3af3b81ff747b857621 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Wed, 17 Sep 2025 17:52:29 +0900 Subject: [PATCH 1/3] Fix titlebar gap under caption buttons --- WinUIGallery/MainWindow.xaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WinUIGallery/MainWindow.xaml b/WinUIGallery/MainWindow.xaml index 6a7d12f06..da5768639 100644 --- a/WinUIGallery/MainWindow.xaml +++ b/WinUIGallery/MainWindow.xaml @@ -13,6 +13,9 @@ + + 46 + From b148634fb16e294499bd4f46a0fa6991527bdb8b Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 19 Sep 2025 11:03:52 +0900 Subject: [PATCH 2/3] Revert "Fix titlebar gap under caption buttons" This reverts commit e4162eeeb6919d39bef0e3af3b81ff747b857621. --- WinUIGallery/MainWindow.xaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/WinUIGallery/MainWindow.xaml b/WinUIGallery/MainWindow.xaml index da5768639..6a7d12f06 100644 --- a/WinUIGallery/MainWindow.xaml +++ b/WinUIGallery/MainWindow.xaml @@ -13,9 +13,6 @@ - - 46 - From 0f16190426799313164b95c11498caefcc4f628d Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 19 Sep 2025 11:49:26 +0900 Subject: [PATCH 3/3] Adjust NavigationView margin based on window state Added `WindowPresenter` and `CurrentWindowState` properties to track and manage the window's presentation state. Updated the `MainWindow` constructor to initialize these properties and adjust the `NavigationView` margin dynamically. Introduced the `AdjustNavigationViewMargin` method to handle margin adjustments when the window state changes, ensuring proper alignment of the `NavigationView` with the caption buttons. --- WinUIGallery/MainWindow.xaml.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index 0dda5d96e..95ba6e764 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -32,12 +32,35 @@ public NavigationView NavigationView public Action NavigationViewLoaded { get; set; } + private OverlappedPresenter WindowPresenter { get; init; } + + private OverlappedPresenterState CurrentWindowState { get; set; } + public MainWindow() { this.InitializeComponent(); SetWindowProperties(); RootGrid.ActualThemeChanged += (_, _) => TitleBarHelper.ApplySystemThemeToCaptionButtons(this, RootGrid.ActualTheme); dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); + + WindowPresenter = AppWindow.Presenter as OverlappedPresenter; + CurrentWindowState = WindowPresenter.State; + AdjustNavigationViewMargin(force: true); + AppWindow.Changed += (_, _) => AdjustNavigationViewMargin(); + } + + // Adjusts the NavigationView margin based on the window state to fix the gap between the caption buttons and the NavigationView. + private void AdjustNavigationViewMargin(bool? force = null) + { + if (WindowPresenter.State == CurrentWindowState && force is not true) + { + return; + } + + NavigationView.Margin = WindowPresenter.State == OverlappedPresenterState.Maximized + ? new Thickness(0, -1, 0, 0) + : new Thickness(0, -2, 0, 0); + CurrentWindowState = WindowPresenter.State; } private void RootGrid_Loaded(object sender, RoutedEventArgs e)