Popup ignores PlacementMode when creating window, resulting in incorrect DPI
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
When popups are created for PerMonitor DPI enabled apps, WPF will always choose the monitor containing the Top, Left of the PlacementTarget regardless of PlacementMode.
### Reproduction Steps
Enable per-monitor dpi in app.manifest
```
true
PerMonitorV2
```
Implement a simple Popup that can be respawned
```
public partial class MainWindow : Window
{
Popup popup;
public MainWindow()
{
InitializeComponent();
popup = new Popup();
popup.Child = new Border() { Width = 100, Height = 100, Background = new SolidColorBrush() { Color = Color.FromRgb(255, 0, 0) } };
popup.PlacementTarget = this;
popup.Placement = PlacementMode.MousePoint;
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Space)
{
popup.IsOpen = false;
popup.IsOpen = true;
}
}
}
```
_Using a monitor setup of (Left: 175%, Right: 100%)_
1. Position the window's Top, Left onto the left monitor.
2. Repeatadly press Space while moving the mouse between monitors: observe the popup mainting it's 175% scaling regardless of mouse position.
3. Position the window's Top, Left onto the Right monitor.
4. Repeat step 2: observe the popup maintains a 100% scaling.
### Expected behavior
Popups should be created on the monitor containing the real PlacementOrigin.
Resulting in a popup window with the correct initial Dpi scaling
### Actual behavior
Popups are created on the monitor containing the Top, Left of the PlacementTarget
Resulting in a potentially inaccurate initial Dpi scaling
### Regression?
Doesn't look like it.
### Known Workarounds
Unassigning the PlacementTarget can gaurentee the Popup is created on the Primary monitor and scaling can be done manually.
### Impact
Fairly minor visual bug.
### Configuration
- Which version of .NET is the code running on? **.Net 6**
- What OS and version, and what distro if applicable? **Windows 10 22H2**
- What is the architecture (x64, x86, ARM, ARM64)? **x64**
- Do you know whether it is specific to that configuration? **This shouldn't be specific to a configuration**
### Other information
Issue seems to stem from [here](https://github.com/dotnet/wpf/blob/026f338641b847dace824f36376beae5f5ad021a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs#L3573)
Contributor guide
Assessment
This issue has not been assessed yet.