maui blazor app启动位置和窗口大小

xingyun86 2023-5-25 855

maui blazor app启动位置和窗口大小

using Microsoft.Extensions.Logging;
using MauiApp1.Data;
using Microsoft.Maui.LifecycleEvents;
namespace MauiApp1;
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(windows => windows
        .OnWindowCreated(window =>
                {
					MauiWinUIWindow mauiwin = window as MauiWinUIWindow;
					if (mauiwin == null) { return; }
					var wndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(mauiwin.WindowHandle);
					Microsoft.UI.Windowing.AppWindow appwin = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(wndId);
					var ScreenHeight = Microsoft.UI.Windowing.DisplayArea.Primary.WorkArea.Height;
					var ScreenWidth = Microsoft.UI.Windowing.DisplayArea.Primary.WorkArea.Width;
					appwin.MoveAndResize(new Windows.Graphics.RectInt32((int)(ScreenWidth - 800)/2, (int)(ScreenHeight - 600)/2, 800, 600));
                }));    
#endif
            });
        builder.Services.AddMauiBlazorWebView();
#if DEBUG
		builder.Services.AddBlazorWebViewDeveloperTools();
		builder.Logging.AddDebug();
#endif
		builder.Services.AddSingleton<WeatherForecastService>();
		return builder.Build();
	}
}


×
打赏作者
最新回复 (0)
查看全部
全部楼主
返回