MAUI+Blazor:隐藏标题栏和问题

前言

最近在研究MAUI+Blazor开发,发现一个问题,原生的的标题栏实在是太丑了。

相关文章

MAUI桌面端标题栏设置和窗口调整

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?

代码

在这里插入图片描述
在这里插入图片描述

#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

边框去除成功!
在这里插入图片描述

问题

但是有一个问题,就是无法拖动整个窗口了。
后来我才知道,为什么Windows平台专门有这个东西了,原因就是因为他帮我们封装了:

  • 窗口拖动
  • 窗口缩放
  • 窗口隐藏
  • 关闭窗口

这四个功能,如果我们隐藏了标题栏,那么我们就要重新写一下这四个功能了。如果有特殊需求那就需要定制才行。如果我们用Blazor去写,我们就要重新写这四个功能。我过段时间研究一下怎么解决。

有必要解决吗?

其实没多大必要解决,除非你想把标题栏改的很复杂,不然没必要这么做。因为MAUI+Blazor开发讲究的就是一个快。我视图层用Blazor去展示,然后间接调用C#代码。视图逻辑Blazor自己解决。真想定制标题栏就把标题栏隐藏了自己重新就行了。

猜你喜欢

转载自blog.csdn.net/qq_44695769/article/details/132266838
今日推荐