Skip to content

Scaling and/or resolution changes on Windows when WindowState.Maximized #19434

@ia-alpatov

Description

@ia-alpatov

Describe the bug

Incorrent behavoir on changing scaling and/or resolution on Windows, when WindowState.Maximized.

After scaling down (from 150% to 100%):
scaling down

After scaling up (from 150% to 175%) it acts as WindowState.Fullscreen

And same for changing screen resolution up and down.

To Reproduce

Step to reproduce:

  1. Create project with latest prerealse Avalonia
  2. Change App.xaml.cs code
  3. Run and change resolution or scaling
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Avalonia.Threading;

namespace Avalonia.Windows.Scaling.Bug;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow()
            {
                WindowState = WindowState.Maximized,
                ExtendClientAreaToDecorationsHint = false,
                ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome,
                ExtendClientAreaTitleBarHeightHint = -1,
                SystemDecorations = SystemDecorations.None
            };
        }

        base.OnFrameworkInitializationCompleted();
    }
}

Expected behavior

Window stays maximized

Avalonia version

12.0.999-cibuild0058128-alpha

OS

Windows

Additional context

Repo with minimal bug.

Possible method with bug

Dirty and temporary fix:

desktop.MainWindow.ScalingChanged += (s, e) =>
                  {
                      desktop.MainWindow.WindowState = WindowState.Minimized;
                      Dispatcher.UIThread.InvokeAsync(() =>
                      {
                          desktop.MainWindow.WindowState = WindowState.Maximized; 
                          desktop.MainWindow.Focus();
                      });
                  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp-wantedA contribution from the community would be most welcome.os-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions