How do I Maximize the Windows Screen in a .NET MAUI App

Fritz Switzer 321 Reputation points
2023-12-28T22:52:32.7566667+00:00

I want my .NET Maui app to run as a Mazimized window. How do I accomplish this?

I tried using this code but it wants a DLLImport code?

 Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
        {
#if WINDOWS
            var nativeWindow = handler.PlatformView;
            nativeWindow.Activate();
            IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
            ShowWindow(windowHandle, 3);
#endif
        });

      
    }
#if WINDOWS
    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
#endif
Windows development Windows App SDK
Developer technologies .NET .NET MAUI
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-12-29T02:34:49.0333333+00:00

    Hello,

    For the full-screen requirement of the Windows platform, you can refer to the following code.

    #if WINDOWS
    using Microsoft.UI;
    using Microsoft.UI.Windowing;
    #endif
    
    
    
    // Add this method for builder.
    .ConfigureLifecycleEvents(events =>
    {
    #if WINDOWS
        events.AddWindows(w =>
        {
            w.OnWindowCreated(window =>
            {
                window.ExtendsContentIntoTitleBar = true; //If you need to completely hide the minimized maximized close button, you need to set this value to false.
                IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
                WindowId myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
                var _appWindow = AppWindow.GetFromWindowId(myWndId);
                _appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
            });
        });
    #endif
    });
    
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.