Skip to content

Add window state save/restore feature#2106

Open
Zakariathr22 wants to merge 1 commit intomicrosoft:mainfrom
Zakariathr22:WindowStateSaver
Open

Add window state save/restore feature#2106
Zakariathr22 wants to merge 1 commit intomicrosoft:mainfrom
Zakariathr22:WindowStateSaver

Conversation

@Zakariathr22
Copy link
Contributor

Description

  • Adds support for saving and restoring main window size, position, scale, and maximized state between sessions.
  • Introduces new settings properties and UI toggle for enabling/disabling this feature.
  • Implements WindowStateHelper and WindowState classes for state management.
  • Window state is restored on load and saved on close if enabled in Settings page.

Motivation and Context

How Has This Been Tested?

Manually tested

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Adds support for saving and restoring main window size, position, scale, and maximized state between sessions. Introduces new settings properties and UI toggle for enabling/disabling this feature. Implements `WindowStateHelper` and `WindowState` classes for state management. Window state is restored on load and saved on close if enabled.
@niels9001
Copy link
Collaborator

@Zakariathr22 I haven't tested this yet, will do soon! How will this work when moving between monitors? E.g. opening the app on multi-monitor setup, and then unplugging and only using the laptop's screen?

@Zakariathr22
Copy link
Contributor Author

@Zakariathr22 I haven't tested this yet, will do soon! How will this work when moving between monitors? E.g. opening the app on multi-monitor setup, and then unplugging and only using the laptop's screen?

I tested it, and the window consistently reopens on the main screen after being closed and launched again.

How the code works:

  • Retrieves the AppWindow instance.
  • Uses XamlRoot.RasterizationScale to account for DPI scaling, ensuring the window maintains the same physical size across different monitors.
  • Before saving the window state, it temporarily restores the window if it is maximized. This ensures the actual window size is saved rather than the maximized dimensions.
  • When restoring the window state, it validates the saved position against the display area bounds to keep the window fully visible and prevent it from appearing partially off-screen or on a disconnected monitor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resize the window on startup

2 participants