Ability to set initial window size and position and restore previous values
See original GitHub issueDescription
I wish to be able to define a default starting size and position for the MAUI application and to restore the window position and size the next time the application is launched.
While I understand the paradigm of starting MAUI apps as full-screen (or close to full screen), it is very impractical for users to have ultra-wide monitors (in my case a 49" 5440x1440 monitor); I literally have to turn my head to change from the left side to the right side of the monitor.
I have a work-around for the initial window size and position* (except for not being able to determine the screen size, so I cannot do bounds checking to make sure the window is wholly within the screen for different resolutions / monitor sizes) but would prefer to have official support, cross platform to MacOS, for this functionality.
Public API Changes
int initialWidth = 1024;
int initialHeight = 726;
Screen primary = Screen.GetPrimaryScreen(); // New API
RectInt32 sizeAndPosition = new RectInt32(
primary.Width/2 - initialWidth/2,
primary.Height/2 - initialHeight/2,
initialWidth,
initialHeight);
Window window = new Window(new SomePage(), sizeAndPosition); // New API
Intended Use-Case
My app has two distinct modes of operation; Full mode for Desktop environments (Windows / MacOS) and Player for mobile devices (Android / iOS). On desktop environments (Windows / MacOS), full screen is not a desired initial state for the application.
If the user has resized and positioned the window in a specific location of the screen - as long as that position + size is still valid the application should re-launch to that position and size.
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:6 (4 by maintainers)
Top GitHub Comments
One thing I noticed today, mac catalyst already save window size and position. So this is probably more just for windows.
Granted - as long as the system is able to do bounds check to validate that the restored position of the window falls within a valid range and doesn’t restore to an off-screen location.
Example:
In this case, it would be perfectly acceptable for the app to be opened in the valid screen, then either get its “default sizing” (behavior we see today) or retain the size it had before if the size can be contained within the screen bounds (minus the task bar).