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

1,2번의 과정으로 관리자 권한을 얻을 수 있다.

 

1.

app.manifest 파일에 

<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

구문 추가

 

<?xml version="1.0" encoding="utf-8"?>

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">

  <assemblyIdentity version="1.0.0.0" name="MauiApp3.WinUI.app"/>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">

<security>

<requestedPrivileges>

<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

</requestedPrivileges>

</security>

</trustInfo>

  <application xmlns="urn:schemas-microsoft-com:asm.v3">

    <windowsSettings>

      <!-- The combination of below two tags have the following effect:

           1) Per-Monitor for >= Windows 10 Anniversary Update

           2) System < Windows 10 Anniversary Update

      -->

      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>

      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>

    </windowsSettings>

  </application>

</assembly>

 

 

---

2.

Package.appxmanifest 파일에

  <rescap:Capability Name="allowElevation" />

구문 추가

 

<?xml version="1.0" encoding="utf-8"?>

<Package

  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"

  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"

  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"

  IgnorableNamespaces="uap rescap">

 

  <Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />

 

  <Properties>

    <DisplayName>$placeholder$</DisplayName>

    <PublisherDisplayName>User Name</PublisherDisplayName>

    <Logo>$placeholder$.png</Logo>

  </Properties>

 

  <Dependencies>

    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />

    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />

  </Dependencies>

 

  <Resources>

    <Resource Language="x-generate" />

  </Resources>

 

  <Applications>

    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">

      <uap:VisualElements

        DisplayName="$placeholder$"

        Description="$placeholder$"

        Square150x150Logo="$placeholder$.png"

        Square44x44Logo="$placeholder$.png"

        BackgroundColor="transparent">

        <uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />

        <uap:SplashScreen Image="$placeholder$.png" />

      </uap:VisualElements>

    </Application>

  </Applications>

 

  <Capabilities>

  <rescap:Capability Name="runFullTrust" />

  <rescap:Capability Name="allowElevation" />

  </Capabilities>

 

</Package>

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

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

+ Recent posts