Reputation: 89
There is already a solution for windows, I need something similar, but for MacOS; Solution for Windows: MAUI .NET Set Window Size
Upvotes: 2
Views: 2392
Reputation: 21
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);
});
});
});
}
Upvotes: 2
Reputation: 89
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);
});
});
});
}
Upvotes: 2