来源:https://www.saoniuhuo.com/question/detail-2593977.html
方式1 MainPage.xaml对应的cs文件中
namespace XCGMauiApp { public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } protected override void OnHandlerChanged() { base.OnHandlerChanged(); //设置 windows 下自动全屏显示 https://www.saoniuhuo.com/question/detail-2593977.html #if WINDOWS var window = App.Current.Windows.FirstOrDefault().Handler.PlatformView as Microsoft.UI.Xaml.Window; IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window); Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle); Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); //全屏显示,无最大化、最小化、关闭栏。无窗体外壳。 //ppWindow.SetPresenter(Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen); //最大化,有窗体外壳。 (appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).Maximize(); // this line can maximize the window #endif } } }
方式2 MauiProgram.cs中build
//设置 windows 下自动全屏显示 https://www.saoniuhuo.com/question/detail-2593977.html //#if WINDOWS // builder.ConfigureLifecycleEvents(events => // { // events.AddWindows(wndLifeCycleBuilder => // { // wndLifeCycleBuilder.OnWindowCreated(window => // { // //window.ExtendsContentIntoTitleBar = false; // IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window); // Microsoft.UI.WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd); // var _appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId); // //全屏显示,无最大化、最小化、关闭栏。无窗体外壳。 // //_appWindow.SetPresenter(Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen); // //if you want to full screen, you can use this line // //最大化,有窗体外壳。 // (_appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).Maximize(); // //if you want to Maximize the window, you can use this line // }); // }); // }); //#endif
标签:windows,Windowing,appWindow,window,UI,全屏,MAUI,Microsoft From: https://www.cnblogs.com/xsj1989/p/18127110