Although the issue dose not appear on all windows 11 machines and I don't know why, here is the solution:
By adding the following lines to the MauiProgram.cs to be able to call the function
SetBorderAndTitleBar(false, false);
the problem was fixed. ( Just the lines between #If Windows and #endif.)
/// Need to use the 2 following name spaces:
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
#endif
namespace MauiAppWindowTest
{
public static class MauiProgram
{
public static bool NoTitleBar=false;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
/// The Code below was added
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow appWindow = AppWindow.GetFromWindowId(win32WindowsId);
if (appWindow.Presenter is OverlappedPresenter p)
{
/// Calling this function resolves the issue
p.SetBorderAndTitleBar(false, false);
}
});
});
});
#endif
/// Up to Here
return builder.Build();
}
}
}