You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this has mostly to do with the fact that the lifecycle is a little different with .NET MAUI. You totally can do this, but not exactly the same as with WinUI.
What you want to do is hook into the lifecycle events we have setup for windows (note: a window, not Windows). You can do that in the MauiProgram when the app is setup:
publicstatic MauiApp CreateMauiApp(){varbuilder= MauiApp.CreateBuilder();
builder
.UseMauiApp<App>().ConfigureFonts(fonts =>{ fonts.AddFont("OpenSans-Regular.ttf","OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf","OpenSansSemibold");});
#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;varhandle= WinRT.Interop.WindowNative.GetWindowHandle(window);varid= Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);varappWindow= Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);switch(appWindow.Presenter){case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter: overlappedPresenter.SetBorderAndTitleBar(false,false); overlappedPresenter.Maximize();break;}});});});
#endif
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();}
The important part is in the #if WINDOWS block. First we set the ExtendsContentIntoTitleBar to false. I think that might be the cause of the small titlebar that you still see in your scenario. Maybe setting that for you is even enough. From there, I think we're doing pretty much the same thing to get the window handle, window, etc. and then set the right properties on the Presenter. Of course if you want to make this specific to one type of window or just one window you'll have to implement some logic to only do it for that window.
Coincidentally I have written about it here: https://blog.verslu.is/maui/full-screen-disable-minimize-maximize-for-net-maui-windows-apps/ with the code being here: https://github.com/jfversluis/MauiWindowsFullscreenMinimizeMaximizeSample
What you want to do is hook into the lifecycle events we have setup for windows (note: a window, not Windows). You can do that in the
MauiProgram
when the app is setup:The important part is in the
#if WINDOWS
block. First we set theExtendsContentIntoTitleBar
to false. I think that might be the cause of the small titlebar that you still see in your scenario. Maybe setting that for you is even enough. From there, I think we're doing pretty much the same thing to get the window handle, window, etc. and then set the right properties on thePresenter
. Of course if you want to make this specific to one type of window or just one window you'll have to implement some logic to only do it for that window.The above is for opening the window initially, you can also do it on some user interaction. That code with different scenarios can be found here: https://github.com/jfversluis/MauiWindowsFullscreenMinimizeMaximizeSample/blob/main/MauiWindowsFullscreenMinimizeMaximizeSample/MainPage.xaml.cs
If there is anything still missing from this feel free to reach out and/or open a new issue with that specific scenario.
Thanks!
Originally posted by @jfversluis in #10057 (comment)
After using this solution now appear white top line (artefact). How fix it?
Code:
The text was updated successfully, but these errors were encountered: