Fixed the initial window size for Windows

This commit is contained in:
Thorsten Sommer 2022-08-14 14:37:40 +02:00
parent 2f72fc5e7f
commit 3055752940
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -1,4 +1,12 @@
namespace UI_MAUI;
using Microsoft.Maui.LifecycleEvents;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif
namespace UI_MAUI;
public static class MauiProgram
{
@ -11,6 +19,25 @@ public static class MauiProgram
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
var nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
var win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
var appWindow = AppWindow.GetFromWindowId(win32WindowsId);
const int width = 1366;
const int height = 768;
appWindow.ResizeClient(new SizeInt32(width, height));
});
});
});
#endif
builder.Services.AddMauiBlazorWebView();
#if DEBUG