简体   繁体   English

如何隐藏或删除 MAUI Blazor Hybrid 上的标题栏

[英]How to hide or remove title bar on MAUI Blazor Hybrid

I wanna remove title bar.我想删除标题栏。 I tried我试过了

#if WINDOWS events.AddWindows(wndLifeCycleBuilder => { wndLifeCycleBuilder.OnWindowCreated(window => { window.ExtendsContentIntoTitleBar = false; }); }); #if WINDOWS events.AddWindows(wndLifeCycleBuilder => { wndLifeCycleBuilder.OnWindowCreated(window => { window.ExtendsContentIntoTitleBar = false; }); }); #endif #万一

but this doesn't work.但这不起作用。 How to remove system title bar on the top of application?如何去除应用程序顶部的系统标题栏? I mean about this bar.我是说这个酒吧。 在此处输入图像描述

Per Radzuixo's solution, this can be achieved by setting SetBorderAndTitleBar(Boolean, Boolean) to false and then set ExtendsContentIntoTitleBar to false .根据 Radzuixo 的解决方案,这可以通过将SetBorderAndTitleBar(Boolean, Boolean)设置为false然后将ExtendsContentIntoTitleBar设置为false来实现。 Please use the MauiProgram.cs like below:请像下面这样使用MauiProgram.cs

using MauiApp13blazor.Data; 
using Microsoft.Maui.LifecycleEvents;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif

namespace MauiApp13blazor;

public static class MauiProgram
{
      public static MauiApp CreateMauiApp()
      {
            var builder = MauiApp.CreateBuilder();
            builder
                  .UseMauiApp<App>()
                  .ConfigureFonts(fonts =>
                  {
                        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                  })

  .ConfigureLifecycleEvents(events =>

        {


#if WINDOWS

            events.AddWindows(wndLifeCycleBuilder =>

            {               

                wndLifeCycleBuilder.OnWindowCreated(window =>

                {

                    IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);

                    WindowId nativeWindowId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);

                    AppWindow appWindow = AppWindow.GetFromWindowId(nativeWindowId);

                    var p = appWindow.Presenter as OverlappedPresenter;
                  
                    window.ExtendsContentIntoTitleBar = false;

                    p.SetBorderAndTitleBar(false, false);

                });

            });

#endif

        });


        builder.Services.AddMauiBlazorWebView();
#if DEBUG
            builder.Services.AddBlazorWebViewDeveloperTools();
#endif
            
            builder.Services.AddSingleton<WeatherForecastService>();

            return builder.Build();
      }
}

I resolved my problem by edit MauiProgram.cs我通过编辑 MauiProgram.cs 解决了我的问题

        builder.ConfigureLifecycleEvents(events =>
        {

#if WINDOWS
            events.AddWindows(wndLifeCycleBuilder =>
            {                
                wndLifeCycleBuilder.OnWindowCreated(window =>
                {
                    IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                    WindowId nativeWindowId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
                    AppWindow appWindow = AppWindow.GetFromWindowId(nativeWindowId);
                    var p = appWindow.Presenter as OverlappedPresenter;

                    window.ExtendsContentIntoTitleBar = false;
                    window.CenterOnScreen(400, 750);
                    p.SetBorderAndTitleBar(false, false);
                });
            });
#endif
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM