question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to set initial window size and position and restore previous values

See original GitHub issue

Description

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:open
  • Created a year ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mattleibowcommented, Apr 3, 2023

One thing I noticed today, mac catalyst already save window size and position. So this is probably more just for windows.

1reaction
Shrp77commented, Jun 3, 2022

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:

  • Laptop with a second monitor attached.
  • Move the app to the second monitor and close the app.
  • Disconnect the second monitor.
  • Launch the app.

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset the window position of an application
When the window has focus, try ALT+SPACE to open the context menu. There you should see the options which usually include move/minimize/maximize ...
Read more >
4 Ways to Remember Window Size and Position in ...
Make Windows 10 remember the window position and size of your desktop apps by using SmartWindows. It automates screen arrangement and ...
Read more >
How to set default size for Open/Save.... window?
Type EHSHELL and Press Enter. Resize window into a long oblong window with the cursor hovering, and next press CTRL key while Closing...
Read more >
Windows does not remember window position and size
Windows does not remember window position and size · Use Shift key while closing a window · Restore previous folder windows at logon...
Read more >
NET / Windows Forms: remember windows size and location
Location ; Size = Properties.Settings.Default.Size; }. It will restore the last state. It even remembers which monitor in a multi monitor set ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found