From d8eb12fab0dd1adf9305edeb31f5a7685f8b9960 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Sat, 21 Mar 2026 19:55:54 +0800 Subject: [PATCH] feat: preserve window state before entering fullscreen mode. --- .../Chrome/WindowDrawnDecorations.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/Chrome/WindowDrawnDecorations.cs b/src/Avalonia.Controls/Chrome/WindowDrawnDecorations.cs index 48847b5f59..179389a3bb 100644 --- a/src/Avalonia.Controls/Chrome/WindowDrawnDecorations.cs +++ b/src/Avalonia.Controls/Chrome/WindowDrawnDecorations.cs @@ -138,6 +138,7 @@ public class WindowDrawnDecorations : StyledElement private IDisposable? _windowSubscriptions; private Window? _hostWindow; private double _titleBarHeightOverride = -1; + private WindowState _stateBeforeFullScreen = WindowState.Normal; /// /// Raised when any property affecting the effective geometry changes @@ -523,10 +524,18 @@ public class WindowDrawnDecorations : StyledElement private void OnFullScreenButtonClick(object? sender, Interactivity.RoutedEventArgs e) { if (_hostWindow != null) - _hostWindow.WindowState = _hostWindow.WindowState == WindowState.FullScreen - ? WindowState.Normal - : WindowState.FullScreen; - e.Handled = true; + { + if (_hostWindow.WindowState != WindowState.FullScreen) + { + _stateBeforeFullScreen = _hostWindow.WindowState; + _hostWindow.WindowState = WindowState.FullScreen; + } + else + { + _hostWindow.WindowState = _stateBeforeFullScreen; + } + e.Handled = true; + } } private void UpdateMaximizeButtonState()