There is already a solution for windows, I need something similar, but for MacOS; Solution for Windows: MAUI .NET Set Window Size
Asked
Active
Viewed 1,994 times
2 Answers
2
I independently found the answer to the question, below I attached the code:
private void SetMainWindowStartSize(int width, int height)
{
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(
nameof(IWindow), (handler, view) =>
{
var size = new CoreGraphics.CGSize(width, height);
handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size;
handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size;
Task.Run(() =>
{
Thread.Sleep(1000);
MainThread.BeginInvokeOnMainThread(() =>
{
handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = new CoreGraphics.CGSize(100, 100);
handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = new CoreGraphics.CGSize(5000, 5000);
});
});
});
}

Aleksandr
- 79
- 5
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 13 '22 at 05:17
2
I am not sure where you found this.; It works for me in MacOs, kudos. For me the complete solution in context. I added this function to MainPage.xaml.cs
Note: This is a MACOS specific feature. It needs platform specific wrapping.
Then I called the initial size I wanted in the mainpage function.
public MainPage()
{
InitializeComponent();
SetMainWindowStartSize(300, 150);
}
private void SetMainWindowStartSize(int width, int height)
{
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(
nameof(IWindow), (handler, view) =>
{
var size = new CoreGraphics.CGSize(width, height);
handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size;
handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size;
Task.Run(() =>
{
Thread.Sleep(1000);
MainThread.BeginInvokeOnMainThread(() =>
{
handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = new CoreGraphics.CGSize(100, 100);
handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = new CoreGraphics.CGSize(5000, 5000);
});
});
});
}

Gizmo-Cal
- 21
- 2