c#/MAUI

[MAUI] windows에서 실행시 전체화면 처리하기

Choi Jaeho 2023. 6. 27. 13:14
반응형

MauiProgrma.cs 에 아래(#if winodws 부터)를 추가한다.

FullScreen 은 창이 화면을 꽉 채우게 되어 최소화 최대화 버튼이 보이지 않는 상태이고

Maximize 는 전체 화면으로 최소화 최대화 버튼 등이 보인다.

            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });
#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

 

혹은 

MainPage.cs 에서 동일한 내용을 

OnHandlerChanged() 에 추가해서도 사용 가능하다.

protected override void OnHandlerChanged()
      {
            base.OnHandlerChanged();
#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);
                appWindow.SetPresenter(Microsoft.UI.Windowing.AppWindowPresenterKind.FullScreen);
            //   (appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).Maximize();
            // this line can maximize the window
#endif
      }
반응형

'c# > MAUI' 카테고리의 다른 글

Maui windows admin 권한 얻기  (0) 2022.08.14