Smit Rathod
Smit Rathod

Reputation: 143

How To Disable "Restore Down" In .NET MAUI Blazor Component App

I have created one .NET MAUI Blazor Component App.

I want to restrict user to not to restore down the window. Simply, I want to disable below button in Windows as well as MAC Catalyst.

enter image description here

Also I want to force application to open it in maximized window for Windows & MAC Catalyst.

How to achieve this?

Upvotes: 0

Views: 142

Answers (1)

Guangyu Bai - MSFT
Guangyu Bai - MSFT

Reputation: 4576

You can use the code below in the MauiProgram.cs. It can disable the maximize button on the windows platform and make the window maximize.

#if WINDOWS
        builder.ConfigureLifecycleEvents(events =>
        {
            // Make sure to add "using Microsoft.Maui.LifecycleEvents;" in the top of the file
            events.AddWindows(windowsLifecycleBuilder =>
            {
                windowsLifecycleBuilder.OnWindowCreated(window =>
                {
                    window.ExtendsContentIntoTitleBar = false;
                    var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                    var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
                    var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
                    switch (appWindow.Presenter)
                    {
                        case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                            overlappedPresenter.Maximize();
                            overlappedPresenter.IsMaximizable = false;
                            break;
                    }
                });
            });
        });
#endif

Upvotes: 1

Related Questions