maui icon indicating copy to clipboard operation
maui copied to clipboard

Mac Catalyst does not support resizing or repositioning windows programmatically

Open mattleibow opened this issue 2 years ago • 13 comments

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

  1. Set Window.Width = 400
  2. 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

mattleibow avatar Aug 26 '22 23:08 mattleibow

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.

ghost avatar Aug 31 '22 16:08 ghost

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

angelru avatar Sep 16 '22 11:09 angelru

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 ?

arkadym avatar Sep 20 '22 07:09 arkadym

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 avatar Sep 20 '22 08:09 angelru

@angelru could i trouble you to try hide titlebar ? Will it work with your method ?

arkadym avatar Sep 20 '22 08:09 arkadym

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

mattleibow avatar Sep 22 '22 04:09 mattleibow

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?

headintheclouds21 avatar Nov 08 '22 21:11 headintheclouds21

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?

4or5trees avatar Nov 24 '22 10:11 4or5trees

@angelru could i trouble you to try hide titlebar ? Will it work with your method ?

Did you find a solution on this?

sagemodeninja avatar Jan 23 '23 12:01 sagemodeninja

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.

mattleibow avatar Jan 25 '23 07:01 mattleibow

@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?

mattleibow avatar Jan 25 '23 07:01 mattleibow

Verified this issue with Visual Studio for Mac 17.6.2 (build 414). Can repro on macOS platform.

jinxinjuan avatar Aug 07 '23 09:08 jinxinjuan

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?

By calling OpenWIndow() works but we also lost the ability of resizing after app launched.

WisJamison avatar Nov 17 '23 07:11 WisJamison