I'm working on a .NET MAUI app which I'd like to deploy on Windows beside Android.
My goal is to specify a minimal window width and a minimal window height only
affecting Windows as a platform.
My attempt to set the aforementioned properties inside App.xamls.cs
:
public App()
{
InitializeComponent();
Microsoft.Maui.Handlers.WindowHandler.WindowMapper[nameof(IWindow)] = (handler, view) =>
{
#if WINDOWS
var nativeWindow = handler.NativeView;
nativeWindow.Activate();
IntPtr windowHandle = PInvoke.User32.GetActiveWindow();
PInvoke.User32.SetWindowPos(windowHandle,
PInvoke.User32.SpecialWindowHandles.HWND_TOP,
0, 0, width, height, // width and height are ints
PInvoke.User32.SetWindowPosFlags.SWP_NOMOVE);
#endif
};
}
Unfortunately, it does not work as I'm receiveing the following error:
Error CS0117 'WindowHandler' does not contain a definition for 'WindowMapper
Any help is greatly appreciated!