进入全屏前的窗口状态记录 改为监听 WindowStateChanged

This commit is contained in:
杨劼
2024-07-12 19:03:04 +08:00
parent c25ac53f9b
commit 87707bca1c

View File

@@ -40,6 +40,8 @@ public class CaptionButtons: Avalonia.Controls.Chrome.CaptionButtons
Button.ClickEvent.AddHandler((o, args) => OnRestore(), _restoreButton);
Button.ClickEvent.AddHandler((o, args) => OnMinimize(), _minimizeButton);
Button.ClickEvent.AddHandler((o, args) => OnToggleFullScreen(), _fullScreenButton);
Window.WindowStateProperty.Changed.Subscribe(WindowStateChanged);
if (this.HostWindow is not null && !HostWindow.CanResize)
{
_restoreButton.IsEnabled = false;
@@ -47,13 +49,20 @@ public class CaptionButtons: Avalonia.Controls.Chrome.CaptionButtons
UpdateVisibility();
}
private void WindowStateChanged(AvaloniaPropertyChangedEventArgs<WindowState> e)
{
if (e.NewValue.Value == WindowState.FullScreen)
{
_oldWindowState = e.OldValue.Value;
}
}
protected override void OnToggleFullScreen()
{
if (HostWindow != null)
{
if (HostWindow.WindowState != WindowState.FullScreen)
{
_oldWindowState = HostWindow.WindowState;
HostWindow.WindowState = WindowState.FullScreen;
}
else