.NET MAUI設置windows下自動全屏顯示

來源: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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章