maui
maui copied to clipboard
Mac Catalyst does not support resizing or repositioning windows programmatically
Description
Setting a windows width/height or setting window X/Y does not actually update the window's frame.
This appears to be a limitation in the Mac Catalyst approved APIs.
See also #4942
Steps to Reproduce
- Set
Window.Width = 400
- Observe nothing happens
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
Mac Catalyst
Did you find any workaround?
There may be a potential workaround by setting the Min/Max coordinates and then reverting it. Not perfect, but seems to work OK.
Window.MinimumWidth = 700;
Window.MaximumWidth = 700;
Window.MinimumHeight = 500;
Window.MaximumHeight = 500;
// dispatcher is used to give the window time to actually resize
Dispatcher.Dispatch(() =>
{
Window.MinimumWidth = 0;
Window.MaximumWidth = double.PositiveInfinity;
Window.MinimumHeight = 0;
Window.MaximumHeight = double.PositiveInfinity;
});
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
This doesn't work for me, is it related?
#if MACCATALYST
events.AddiOS(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.SceneWillConnect((scene, session, options) =>
{
if (scene is UIKit.UIWindowScene { SizeRestrictions: { } } windowScene)
{
windowScene.SizeRestrictions.MaximumSize = new CoreGraphics.CGSize(600, 400);
windowScene.SizeRestrictions.MinimumSize = new CoreGraphics.CGSize(600, 400);
}
});
});
#endif
I found this on SO - https://stackoverflow.com/questions/72657602/scenewillconnect-to-session-not-called-after-adding-scenedelegate-into-an-existi According to that we have to set values in Info.plist but there are UISceneDelegateClassName and UISceneStoryboardFile and we need some input from Mac/iOS experienced people. Do any one know how we can handle ?
With this Hanlder it works:
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow),
(handler, view) =>
{
#if MACCATALYST
var size = new CoreGraphics.CGSize(600, 400);
handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size;
handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size;
#endif
});
@angelru could i trouble you to try hide titlebar ? Will it work with your method ?
With maui for net7, there is now also the min/max width/height.
Pity we can't change net6, but at least we get it now
With this Hanlder it works:
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => { #if MACCATALYST var size = new CoreGraphics.CGSize(600, 400); handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size; handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size; #endif });
I'm using .NET 7 and this is not working for me. I've placed it in the app.xaml.cs file with no luck. Has anyone had success with this?
With this Hanlder it works:
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => { #if MACCATALYST var size = new CoreGraphics.CGSize(600, 400); handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size; handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size; #endif });
I'm using .NET 7 and this is not working for me. I've placed it in the app.xaml.cs file with no luck. Has anyone had success with this?
I was able to successfully set the size of a window prior to my call to Application.Current.OpenWindow(wnd)
var myPage = new MyPage();
Window wnd = new Window(myPage);
wnd.MaximumWidth = 300;
wnd.MinimumWidth = 300;
wnd.MaximumHeight = 300;
wnd.MinimumHeight = 300;
Application.Current.OpenWindow(wnd);
Using the MAUI .NET 7 exposed Width
and Height
properties instead of the max/min width/height ones did not work for me.
Has anyone gotten those to work?
@angelru could i trouble you to try hide titlebar ? Will it work with your method ?
Did you find a solution on this?
The width and height properties probably won't ever work as this is not a feature of the os. Not use any apple feels this way, but if anyone finds a way we will try and use that as soon as we can.
There are some hacks, but the easiest way I found was to just set the min and max size to what I want, and then rest then. This appears to work fine.
@angelru could i trouble you to try hide titlebar ? Will it work with your method ?
Did you find a solution on this?
@sagemodeninja can you open a new issue for this one?
Verified this issue with Visual Studio for Mac 17.6.2 (build 414). Can repro on macOS platform.
With this Hanlder it works:
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => { #if MACCATALYST var size = new CoreGraphics.CGSize(600, 400); handler.PlatformView.WindowScene.SizeRestrictions.MinimumSize = size; handler.PlatformView.WindowScene.SizeRestrictions.MaximumSize = size; #endif });
I'm using .NET 7 and this is not working for me. I've placed it in the app.xaml.cs file with no luck. Has anyone had success with this?
I was able to successfully set the size of a window prior to my call to
Application.Current.OpenWindow(wnd)
var myPage = new MyPage(); Window wnd = new Window(myPage); wnd.MaximumWidth = 300; wnd.MinimumWidth = 300; wnd.MaximumHeight = 300; wnd.MinimumHeight = 300; Application.Current.OpenWindow(wnd);
Using the MAUI .NET 7 exposed
Width
andHeight
properties instead of the max/min width/height ones did not work for me.Has anyone gotten those to work?
By calling OpenWIndow() works but we also lost the ability of resizing after app launched.