0

I have a WPF project which draws windows (like popups) over a different app 'APP', according to some elements' position of APP.
Those windows' position is calculated according to the system DPI (aka primary monitor's DPI).
When I change the primary DPI in the display settings, the windows' position is calculated using the 'old' primary DPI, which results in wrong location.
Is there some way to perform these calculations, which depend on the primary DPI, using the 'new' primary DPI and not using the old one?

I know that when changing the primary DPI, windows alerts me that "Some app won't respond to scaling changes until you close and reopen them.", but I need to find a way around it.

Thanks

Alonzzo2
  • 959
  • 10
  • 24

1 Answers1

1

You'll want to look into the SystemEvents.DisplaySettingsChanged event, and write a method that handles that event when it happens. I've done this before in WPF, so I know that it works.

Then, use the answer here by Ana Betts to calculate the primary DPI:

PresentationSource source = PresentationSource.FromVisual(this);

double dpiX, dpiY;
if (source != null) {
    dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
    dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
}
Tam Bui
  • 2,940
  • 2
  • 18
  • 27
  • Actually I already have a good way of getting the primary DPI. What I needed is your answer to subscribe on the DPI change along with a static class which stores the last primary DPI value up until the user changes the settings. This way I always use the 'first' primary DPI. so thank you :) – Alonzzo2 Oct 14 '20 at 18:20