microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.37k stars 680 forks source link

Non resizable window withouth title bar has border when updating to 1.6 #9978

Open DCorrBECare opened 2 months ago

DCorrBECare commented 2 months ago

Describe the bug

With the 1.6 version i get a white border around a window that's not resizable.

Steps to reproduce the bug

Create a window with the following code:

Window window = new();
OverlappedPresenter presenter = OverlappedPresenter.Create();
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(false, false);
window.AppWindow.SetPresenter(presenter);
window.AppWindow.Show();

Expected behavior

There is no border around the window

Screenshots

Window1_5 Window1_6

NuGet package version

WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007

Windows version

Windows 11 (22H2): Build 22621

Additional context

Works fine with WindowsAppSDK 1.5.240802000

Usergitbit commented 1 month ago

Also running into this issue, worked fine on 1.5. Is there any fix / workaround?

DCorrBECare commented 1 month ago

@Usergitbit There is no fix that I'm aware of and I do not now if this will be fixed in the next release.

I guess as a workaround you can manually implement the MaxWidth/MaxHeight/MinWidth/MinHeight on the window, set the window resizable and set the same value to the max and min property. The downside would be that the cursor appears to be resizable on the window when it's actually not.

You can look at this great project for extended features on the Window class.

castorix commented 1 month ago

Also running into this issue, worked fine on 1.5. Is there any fix / workaround?

You can remove the style for the frame :

private IntPtr hWndMain = IntPtr.Zero;

hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
SetWindowLong(hWndMain, GWL_STYLE, (IntPtr)(GetWindowLong(hWndMain, GWL_STYLE) & ~(WS_DLGFRAME)));

with :

        const int GWL_STYLE = (-16);
        const int GWL_EXSTYLE = (-20);
        public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
        {
            if (IntPtr.Size == 4)
            {
                return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
            }
            return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
        }

        [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
        public static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

        [DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
        public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

        public static long GetWindowLong(IntPtr hWnd, int nIndex)
        {
            if (IntPtr.Size == 4)
            {
                return GetWindowLong32(hWnd, nIndex);
            }
            return GetWindowLongPtr64(hWnd, nIndex);
        }

        [DllImport("User32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern long GetWindowLong32(IntPtr hWnd, int nIndex);

        [DllImport("User32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern long GetWindowLongPtr64(IntPtr hWnd, int nIndex);

        public const int WS_DLGFRAME = 0x00400000;
Usergitbit commented 1 month ago

That seems to work for me, thanks @castorix!

bszymik commented 3 weeks ago

Workaround works for me, but still it's a workaround please fix that

Sebbe909 commented 2 weeks ago

Really annoying bug where customers are asking questions to the developer (us) on why their app is "messed up".. Years later and WinUI3 is still terrible

Prochy commented 2 weeks ago

This trick works for me after upgrading 1.6 even though I decided to revert back to 1.5 because of other issues.

ExtendsContentIntoTitleBar = true;
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(true, false);
ghost1372 commented 2 weeks ago

This trick works for me after upgrading 1.6 even though I decided to rollback back to 1.5 because of other issues.

ExtendsContentIntoTitleBar = true;
presenter.IsResizable = false;
presenter.SetBorderAndTitleBar(true, false);

Nice Trick tnx

Lightczx commented 2 weeks ago

Try OverlappedPresenter.CreateForContextMenu()

Lightczx commented 1 week ago

Just did some reverse work: CreateForContextMenu = WS_BORDER CreateForDialog = WS_SYSMENU | WS_CAPTION CreateForToolWindow = WS_OVERLAPPEDWINDOW

IsAlwaysOnTop = WS_EX_TOPMOST IsMaximizable = WS_MAXIMIZEBOX IsMinimizable = WS_MINIMIZEBOX IsModal = Enable/Disable parent Window and some other stuff (restricted to hwnd with owner set) See https://github.com/microsoft/WindowsAppSDK/issues/3258 IsResizable = WS_SIZEBOX(WS_THICKFRAME)