【问题标题】:Maui Blazor window bar removedMaui Blazor 窗口栏已移除
【发布时间】:2022-11-04 15:31:51
【问题描述】:

我实际上正在开发一个在 Windows 上工作的 Maui Blazor 项目,对于这个项目,我创建了一个自定义顶部栏,其中包含一些按钮等......(见下图 2)。

但我想知道如何删除默认窗口栏(参见图片上的 1)。我没有找到可以满足此目的的属性(WPF 除外)。

有小费吗?

谢谢你。

问候,萨米。

【问题讨论】:

  • 答案here 可能会帮助您操作 Windows (WinUI 3) 窗口标题栏。
  • @ToolmakerSteve 我只能更改标题文本。我没有找到完全禁用窗口栏的方法
  • 您可以检查合并的PR。
  • @AlexandarMay-MSFT 当我添加这一行 <TextBlock Height="300">RABBITS</TextBlock> 时,我遇到了 TextBlock 程序集缺失的错误。
  • 请添加到Platforms\Windows\App,xaml。尽管它警告 TextBlock 程序集丢失,但您仍然可以运行它。

标签: windows user-interface window blazor maui


【解决方案1】:

这可以通过将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();
      }
}

【讨论】:

    猜你喜欢
    • 2022-11-04
    • 2022-06-27
    • 1970-01-01
    • 2022-06-20
    • 2023-01-09
    • 2022-01-12
    • 2022-12-14
    • 2022-07-05
    • 2022-10-02
    相关资源
    最近更新 更多