1

I'm actually working on a Maui Blazor project to work on Windows, and for this project, I created a custom top bar, where I include some buttons etc... (see 2 on the picture below).

window default bar removing

But I would like to know how can I remove the default window bar (see 1 on the picture). I didn't found a propertie that can fill this purpose (except for WPF).

Any tips?

Thank you.

Regards, Samih.

Samih EL SAKHAWI
  • 429
  • 4
  • 17

1 Answers1

2

This can be achieved by setting SetBorderAndTitleBar(Boolean, Boolean) to false and then set ExtendsContentIntoTitleBar to false. Please use the MauiProgram.cs like below:

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();
      }
}

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15