1

I am trying to get a totally maximized Window with .NET Maui 8.0.0preview4, but an empty bar remains where the title-bar used to be.

Red - Page, Black - Titlebar

For the example, I've ammended the Maui template by making the "Click me" button toggle the window's maximized state, with the following code inspired by Verslui's article on the topic:

        private void OnCounterClicked(object sender, EventArgs e)
        {
            var window = Window.Handler.PlatformView as MauiWinUIWindow;
            var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
            var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
            var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);

            switch (appWindow.Presenter)
            {
                case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                    if (overlappedPresenter.State == Microsoft.UI.Windowing.OverlappedPresenterState.Maximized)
                    {
                        overlappedPresenter.SetBorderAndTitleBar(true, true);
                        overlappedPresenter.Restore();
                    }
                    else
                    {
                        overlappedPresenter.SetBorderAndTitleBar(false, false);
                        overlappedPresenter.Maximize();
                    }

                    break;
            }
        }

I also scrapped out Shell and use the MainPage directly. Is seems like SetBorderAndTitleBar isn't actually removing the titlebar, just the buttons.

Any ideas for how I can get a true full-screen experience would be much appreciated. Here is the repro repo for those interested. Thanks!

  • 4
    I can reproduce while same code works fine in "pure" WinUI3. Seems like a MAUI limittion, shortcoming or simply a bug. You should post in MAUI github. – Simon Mourier Jun 14 '23 at 14:02
  • 1
    I've made an [issue](https://github.com/dotnet/maui/issues/15676). Fingers crossed! – Aidan Bailey Jun 15 '23 at 12:25

1 Answers1

0

First, add using Microsoft.Maui.LifecycleEvents; in the MauiProgram.cs.

Second, add the code below in the MauiProgram.cs.

#if WINDOWS
        builder.ConfigureLifecycleEvents(events =>
        {
            // Make sure to add "using Microsoft.Maui.LifecycleEvents;" in the top of the file 
            events.AddWindows(windowsLifecycleBuilder =>
            {
                windowsLifecycleBuilder.OnWindowCreated(window =>
                {
                    window.ExtendsContentIntoTitleBar = false;
                    var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                    var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
                    var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
                    switch (appWindow.Presenter)
                    {
                        case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                            break;
                    }
                });
            });
        });
#endif

Then the button will work well.

Guangyu Bai - MSFT
  • 2,555
  • 1
  • 2
  • 8
  • This does not seem to have an effect. – Aidan Bailey Jun 15 '23 at 09:22
  • @AidanBailey - Actually that works for me. I tried `ExtendsContentIntoTitleBar = false` in the onclick event handling but it didn't work there. Seems to be working in the Create event see also https://github.com/dotnet/maui/issues/2190. PS: the rest after `window.ExtendsContentIntoTitleBar = false` is useless – Simon Mourier Jun 15 '23 at 09:48
  • Yes this seems a fix for .NET 7, but remains broken for .NET 8 preview. At least it has no effect when added to my repro. Unless it is working for you in .NET 8? For then I am even more confused. Thanks for both of your help. – Aidan Bailey Jun 15 '23 at 10:56
  • @AidanBailey - I've only tested .NET 7. Maybe it's not too late for Microsoft to fix it for .NET 8 (and maybe document it somehow...) – Simon Mourier Jun 15 '23 at 13:02