Skip to content

Commit

Permalink
fix: fullscreen state bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBabbitt97 committed Jul 25, 2024
1 parent f41020f commit 8bb8851
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/BlazorDesktop/Wpf/BlazorDesktopWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public partial class BlazorDesktopWindow : Window
/// <summary>
/// If the window is fullscreen.
/// </summary>
public bool IsFullscreen => _fullscreen && WindowState == WindowState.Normal;
public bool IsFullscreen { get; private set; }

/// <summary>
/// Occurs when <see cref="IsFullscreen"/> changes.
/// </summary>
public event EventHandler<bool>? OnFullscreenChanged;

private bool _fullscreen;
private WindowState _fullscreenStoredState = WindowState.Normal;
private readonly IServiceProvider _services;
private readonly IConfiguration _config;
Expand Down Expand Up @@ -95,10 +94,10 @@ public void ToggleFullScreen()
{
if (WindowStyle == WindowStyle.SingleBorderWindow)
{
_fullscreen = true;
IsFullscreen = true;
_fullscreenStoredState = WindowState;

UseFrame(_config.GetValue<bool?>(WindowDefaults.Frame) ?? true, _fullscreen);
UseFrame(_config.GetValue<bool?>(WindowDefaults.Frame) ?? true);
WindowStyle = WindowStyle.None;

if (WindowState == WindowState.Maximized)
Expand All @@ -112,9 +111,9 @@ public void ToggleFullScreen()
}
else
{
_fullscreen = false;
IsFullscreen = false;

UseFrame(_config.GetValue<bool?>(WindowDefaults.Frame) ?? true, _fullscreen);
UseFrame(_config.GetValue<bool?>(WindowDefaults.Frame) ?? true);
WindowStyle = WindowStyle.SingleBorderWindow;
WindowState = _fullscreenStoredState;

Expand Down Expand Up @@ -240,7 +239,7 @@ private void InitializeWindow()
MinWidth = minWidth;
MaxHeight = maxHeight;
MaxWidth = maxWidth;
UseFrame(useFrame, _fullscreen);
UseFrame(useFrame);
ResizeMode = (_config.GetValue<bool?>(WindowDefaults.Resizable) ?? true) ? ResizeMode.CanResize : ResizeMode.NoResize;
UseIcon(_config.GetValue<string?>(WindowDefaults.Icon) ?? string.Empty);
Content = WebViewBorder;
Expand Down Expand Up @@ -312,7 +311,7 @@ private void UpdateWebViewBorderThickness()

if (WindowState == WindowState.Maximized && !useFrame)
{
if (_fullscreen)
if (IsFullscreen)
{
WebViewBorder.BorderThickness = new Thickness(7, 7, 7, 7);
}
Expand Down Expand Up @@ -345,11 +344,11 @@ private void UpdateTheme()
}
}

private void UseFrame(bool frame, bool fullscreen)
private void UseFrame(bool frame)
{
if (!frame)
{
if (fullscreen)
if (IsFullscreen)
{
WindowChrome.SetWindowChrome(this, new() { NonClientFrameEdges = NonClientFrameEdges.None });
}
Expand Down

0 comments on commit 8bb8851

Please sign in to comment.