You can read the documentation SetBorderAndTitleBar and Resize:
SetBorderAndTitleBar(Boolean, Boolean) Sets the border and title bar properties of the window.
Resize(SizeInt32) Resizes the window to the specified size.
Your MauiProgram.cs should look like this
using Microsoft.Maui.LifecycleEvents;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif
namespace YourNameSpace
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
window.ExtendsContentIntoTitleBar = false; /*This is important to prevent your app content extends into the title bar area.*/
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow winuiAppWindow = AppWindow.GetFromWindowId(win32WindowsId);
if(winuiAppWindow.Presenter is OverlappedPresenter p)
{
p.SetBorderAndTitleBar(false, false);
}
const int width = 1200;
const int height = 800;
/*I suggest you to use MoveAndResize instead of Resize because this way you make sure to center the window*/
winuiAppWindow.MoveAndResize(new RectInt32(1920 / 2 - width / 2, 1080 / 2 - height / 2, width, height));
});
});
});
#endif
builder.Services.AddMauiBlazorWebView();
return builder.Build();
}
}
}
But the code you need specifically is the one found in the preprocessor directive
#if WINDOWS