Reputation: 1009
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
Upvotes: 0
Views: 800
Reputation: 3048
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;
}
Upvotes: 1