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

Fritz Switzer 261 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 App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
747 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,141 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,574 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,446 Reputation points Microsoft Vendor
    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