Maui Blazor 设置全屏以及去掉标题栏 (Windows 平台)
编辑 MauiProgram.cs 文件
-
隐藏标题栏,隐藏边框
- 已知问题, 可调整大小窗体, 标题栏会残留一点像素作为调整句柄
using Microsoft.Extensions.Logging; using Microsoft.Maui.LifecycleEvents; #if WINDOWS using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml; #endif namespace JovenResApp; public static class MauiProgram { 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"); }); #if DEBUG builder.Logging.AddDebug(); #endif #if WINDOWS builder.ConfigureLifecycleEvents((events) => { events.AddWindows(wndLifeCycleBuilder => { wndLifeCycleBuilder.OnWindowCreated((window) => { if (window.AppWindow.Presenter is OverlappedPresenter p) { //p.IsResizable = false; p.SetBorderAndTitleBar(false, false); } }); }); }); #endif return builder.Build(); } }
-
全屏, 不可调整窗口大小
using Microsoft.Extensions.Logging; using Microsoft.Maui.LifecycleEvents; #if WINDOWS using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml; #endif namespace JovenResApp; public static class MauiProgram { 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"); }); #if DEBUG builder.Logging.AddDebug(); #endif #if WINDOWS builder.ConfigureLifecycleEvents((events) => { events.AddWindows(wndLifeCycleBuilder => { wndLifeCycleBuilder.OnWindowCreated((window) => { window.AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);//全屏 if (window.AppWindow.Presenter is OverlappedPresenter p) { p.IsResizable = false; p.SetBorderAndTitleBar(false, false); } }); }); }); #endif return builder.Build(); } }
-
如果不需要部署为Maui平台,其实可以简单使用 Wpf blazor hybird
简简单单就实现
WindowState="Maximized" WindowStyle="None"
关联项目
FreeSql QQ群:4336577
BA & Blazor QQ群:795206915
Maui Blazor 中文社区 QQ群:645660665
知识共享许可协议
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名AlexChow(包含链接: https://github.com/densen2014 ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系 。
转载声明
本文来自博客园,作者:周创琳 AlexChow,转载请注明原文链接:https://www.cnblogs.com/densen2014/p/18566150