Correct PerMonitorV2 DPI for popups without targets #8209
+8
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3874
Description
When creating a HWND for a popup, it needs to be positioned at the correct monitor to receive its DPI in PerMonitorV2 mode, as noticed and implemented here:
wpf/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs
Lines 1588 to 1599 in 0ef158e
However, when the
PlacemenetTarget
of the popup isnull
, these required steps are not done, since theGetPlacementTargetOriginInScreenCoordinates
gives up and returns 0,0. The popup is then properly positioned after the window is created, which is too late - the winow is potentially created on the wrong monitor, with consequences as above.This PR updates
GetPlacementTargetOriginInScreenCoordinates
to estimate the position that would be used later to position the popup when there is no target. This ensures that the window is created on the correct monitor and the popup will receive correct DPI values.Customer Impact
Only customers using PerMonitorV2 and monitors with at least two different DPIs are affected. For those customers, not taking this PR would mean that popups opened without setting any
PlacementTarget
will open with the primary's monitor DPI.Regression
No.
Testing
Compiled and run using .NET 8.0.0-preview.7.23375.6 with PerMonitorV2 manifest. Verified that setting
ContextMenu.IsOpen
totrue
exhibits the bug on a monitor with different DPI and does not when the PR is applied, using various popup positioning.Risk
I believe this is low, the scenario when the new code executed is very narrow. All of the following must be true:
PlacementTarget
set (this shouldn't be common)IsOpen=true
)Without the PR, the window is created at 0,0 in this case. With the PR, the window is created at a different coordinate. Either way, the window is positioned afterwards to the correct location, so the only observable change is the monitor on which the Win32 window is initially created.
Microsoft Reviewers: Open in CodeFlow