Net Maui Windows How to hide titlebar and custom maximize and minimize events?

Sami 966 Reputation points
2023-11-16T08:29:47.96+00:00

Net Maui Windows How to hide titlebar and custom move maximize and minimize events? thanks..

I have found this for hiding title bar but on top little gray margin problem how we can fix it ?Adsız

            //hide titlebar

#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.SetBorderAndTitleBar(false, false);
                                //overlappedPresenter.Maximize();
                                break;
                        }
                    });
                });
            });
#endif


            ```

also I found this but GetParentWindow()  can not regornize ? Thanks


```csharp
#if WINDOWS
    private Microsoft.UI.Windowing.AppWindow GetAppWindow(MauiWinUIWindow window)
    {
        var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
        var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
        var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
        return appWindow;
    }
#endif

    private void OnToggleFullscreenClicked(object sender, EventArgs e)
	{
#if WINDOWS
		var window = GetParentWindow().Handler.PlatformView as MauiWinUIWindow;
        
        var appWindow = GetAppWindow(window);

        switch (appWindow.Presenter)
        {
            case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                if (overlappedPresenter.State == Microsoft.UI.Windowing.OverlappedPresenterState.Maximized)
                {
                    overlappedPresenter.SetBorderAndTitleBar(true, true);
                    overlappedPresenter.Restore();
                }
                else
                {
                    overlappedPresenter.SetBorderAndTitleBar(false, false);
                    overlappedPresenter.Maximize();
                }

                break;
        }
#endif
    }

    private void OnToggleMaximizeClicked(object sender, EventArgs e)
    {
#if WINDOWS
        var window = GetParentWindow().Handler.PlatformView as MauiWinUIWindow;

        var appWindow = GetAppWindow(window);

        switch (appWindow.Presenter)
        {
            case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                overlappedPresenter.IsMaximizable = !overlappedPresenter.IsMaximizable;
                break;
        }
#endif
    }

    private void OnToggleMinimizeClicked(object sender, EventArgs e)
    {
#if WINDOWS
        var window = GetParentWindow().Handler.PlatformView as MauiWinUIWindow;

        var appWindow = GetAppWindow(window);

        switch (appWindow.Presenter)
        {
            case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                overlappedPresenter.IsMinimizable = !overlappedPresenter.IsMinimizable;
                break;
        }
#endif
    }
Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-11-17T07:30:54.86+00:00

    Hello,

    In order to eliminate this blank space, you will also need to do the following.

    case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
    
        overlappedPresenter.IsMaximizable = false;
        overlappedPresenter.IsResizable = false;
        overlappedPresenter.IsMinimizable = false;
        overlappedPresenter.SetBorderAndTitleBar(false, false);
    

    also I found this but GetParentWindow() can not regornize ? Thanks

    GetParentWindow() is a method that belongs to the Page class. Therefore, you need to put these methods into the ContentPage class, such as MainPage.

    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.


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.