-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add AppContext switch to mirror Owner.TopMost for modal dialogs (restore .NET Framework‑like behavior) #14138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add AppContext switch to mirror Owner.TopMost for modal dialogs (restore .NET Framework‑like behavior) #14138
Conversation
…ore .NET Framework‑like behavior)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds an AppContext switch System.Windows.Forms.MirrorTopMostForModalDialogs to restore .NET Framework-like behavior where modal dialogs temporarily inherit the TopMost property from their owner Form during the modal session.
Key Changes:
- Introduces a new AppContext switch that when enabled, automatically sets TopMost=true on modal dialogs if their owner Form has TopMost=true
- Restores the original TopMost state after the dialog closes
- Default behavior is false to maintain current .NET behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/System.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs |
Adds the MirrorTopMostForModalDialogs switch definition and property |
src/System.Windows.Forms/System/Windows/Forms/Form.cs |
Implements the TopMost mirroring logic in ShowDialog method, capturing original state and restoring it after the modal session |
...ystem.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14138 +/- ##
===================================================
+ Coverage 76.01271% 77.15426% +1.14154%
===================================================
Files 3279 3279
Lines 645325 645337 +12
Branches 47720 47722 +2
===================================================
+ Hits 490529 497905 +7376
+ Misses 145491 143738 -1753
+ Partials 9305 3694 -5611
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Fixes #14101
Proposed changes
System.Windows.Forms.MirrorTopMostForModalDialogs.When enabled,
ShowDialogwill temporarily set the dialog asTopMostif its owner isTopMost, and restore the original state after closing.Default is false to keep current behavior.
Customer Impact
TopMostforms will stay above the owner during the modal session, matching .NET Framework behavior.Regression?
Risk
Screenshots
Before
If the owner is TopMost and the dialog is not, the dialog can be pushed behind the owner during the modal session.

After
Modal dialogs temporarily become TopMost when the owner is TopMost, and stay above the owner until closed.
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow