AvaloniaUI/Avalonia

Window with small width is wrongly shown after update to 11.3.6

FG-rgb opened this issue · 7 comments

Describe the bug

Hello, I'm using a small Window. After update from Avalonia 11.3.5 to 11.3.6 my Window has a wrong width.
I'm setting Width to 63 but it is shown with a width of 100 pixel.

Before the update the width was correct.

To Reproduce

Following settings applyed to the window:

Background="Transparent" SystemDecorations="BorderOnly" TransparencyLevelHint="Transparent" TransparencyBackgroundFallback="LimeGreen" SizeToContent="Manual" ExtendClientAreaToDecorationsHint="True" ExtendClientAreaChromeHints="SystemChrome" ExtendClientAreaTitleBarHeightHint="30" MinWidth="63" MaxWidth="63" Width="63" MinHeight="275" MaxHeight="275" Height="275" CanResize="False"

Strage is, when I call Hide() and then Show() the Window is shown with correct width.

So a workaround is to override the Show method of the window:

public override void Show()
{
base.Show();
Hide();
base.Show();
}

Expected behavior

No response

Avalonia version

11.3.6

OS

Windows

Additional context

I'm using Windows 10 Professional

I'm not able to reproduce your previous behavior on 11.3.5. On my desktop, I'm not able to resize any window, no matter the app to below 136px width. This seems to be the global minimum on my system. Could you post a repro for 11.3.5 and a video for comparison?

Just create a new avalonia project and change window as shown in screenshots

11.3.5
Image

11.3.6
Image

Workaround for 11.3.6

Image
Image

System.TypeLoadException:“Method 'SetCanMinimize' in type 'Avalonia.Win32.WindowImpl' from assembly 'Avalonia.Win32, Version=11.3.3.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b' does not have an implementation.”

Image

System.TypeLoadException:“Method 'SetCanMinimize' in type 'Avalonia.Win32.WindowImpl' from assembly 'Avalonia.Win32, Version=11.3.3.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b' does not have an implementation.”

Make sure your core project and desktop project reference same Avalonia version.

Image System.TypeLoadException:“Method 'SetCanMinimize' in type 'Avalonia.Win32.WindowImpl' from assembly 'Avalonia.Win32, Version=11.3.3.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b' does not have an implementation.”System.TypeLoadException:“类型'Avalonia.Win32.WindowImpl'中的方法'SetCanMinimize'在程序集'Avalonia.Win32, Version=11.3.3.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b'中没有实现。”

Make sure your core project and desktop project reference same Avalonia version.确保您的核心项目和桌面项目引用相同的 Avalonia 版本。

Hey thanks! The error's gone after I restarted VS.

After investigating, I think it's best not to restore the previous behavior, due to much worse side effects.
The previous behavior works because WS_SYSMENU was being removed from windows without a full caption or border. The side effect of it is windows will not provide a system menu, i.e. the menu you get when you right click the window caption, press ALT+Space or window item in the task bar. The other effect is allowing windows to be resized to very small sizes, because the OS doesn't need to care about providing enough space for a caption.
In practice, I have yet to see a main window of an app, with extended client area and border only, that doesn't have a system menu. I think it's not desirable as a default behavior, and the new behavior fixes a more prominent issue. The issue being fixed here, #19620 .
In your case, you can do the following,

const int WS_SYSMENU = 0x80000;

public MainWindow()
{
    InitializeComponent();

    Win32Properties.AddWindowStylesCallback(this, (styles, exStyles) =>
    {
        styles = (uint)(styles & ~WS_SYSMENU);
        return (styles, exStyles);
    });
}

Do note that it will break system menus for that window and may cause your maximized windows to be resizable by the mouse pointer.