MAUI+Blazor: Hide title bar and question

foreword

Recently, I was studying the development of MAUI+Blazor and found a problem. The native title bar is really ugly.

related articles

MAUI desktop title bar setting and window adjustment

MAUI Windows How to completely hide the TitleBar? #15142

MAUI how to remove the Title Bar and fix the window size?
.NET MAUI: Is there a way to hide the Navigation Bar/Title Bar when using Shell?

the code

insert image description here
insert image description here

#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);
                        if (appWindow.Presenter is OverlappedPresenter pre)
                        {
    
    
                            pre.IsMaximizable = false;
                            pre.IsResizable = false;
                            pre.IsMinimizable = false;
                            pre.SetBorderAndTitleBar(false, false);
                        }
                    });
                });
            });
#endif

Border removed successfully!
insert image description here

question

But there is a problem, that is, the entire window cannot be dragged.
Later I found out why the Windows platform has this thing specifically, because it encapsulated it for us:

  • window dragging
  • window zoom
  • window hidden
  • close the window

These four functions, if we hide the title bar, then we have to rewrite these four functions. If you have special needs, you need to customize it. If we use Blazor to write, we have to rewrite these four functions. I'll look into how to fix it in a while.

Is it necessary to solve it?

In fact, there is not much need to solve it, unless you want to change the title bar to be very complicated, otherwise there is no need to do so. Because the development of MAUI+Blazor pays attention to a fast. My view layer uses Blazor to display, and then indirectly calls C# code. The view logic is handled by Blazor itself. If you really want to customize the title bar, just hide the title bar and start over again.

Guess you like

Origin blog.csdn.net/qq_44695769/article/details/132266838