簡體   English   中英

如何隱藏或刪除 MAUI Blazor Hybrid 上的標題欄

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

我想刪除標題欄。 我試過了

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

但這不起作用。 如何去除應用程序頂部的系統標題欄? 我是說這個酒吧。 在此處輸入圖像描述

根據 Radzuixo 的解決方案,這可以通過將SetBorderAndTitleBar(Boolean, Boolean)設置為false然后將ExtendsContentIntoTitleBar設置為false來實現。 請像下面這樣使用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();
      }
}

我通過編輯 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