question

EmonHaque-1485 avatar image
1 Vote"
EmonHaque-1485 asked EmonHaque-1485 edited

PointToScreen with Scaling Problem

I've noticed this issue when working on a secondary Monitor. Here's the two Monitor with different resolution and Scaling:

111324-test1.gif

When I launch the App in Monitor 1, the BusyWindow is positioned correctly:

111289-test2.gif

If I hit Windows + P and select Extend, and move the app to Monitor 2, it also works fine on the Monitor 2:

111304-test3.gif

If I hit Windows + P and select Second screen only, run the app and hit refresh buttons, the BusyWindow opens in wrong position or goes off screen:

111305-test4.gif

How to fix this problem?

EDIT


Looks like the problem is with scaling! I didn't have App.config and app.manifest files in my project, I have added those 2 with following content in App.config:

 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
   <runtime>
     <AppContextSwitchOverrides value ="Switch.System.Windows.DoNotScaleForDpiChanges=false"/>
   </runtime>
 </configuration>

and app.manifest:

 <?xml version="1.0" encoding="utf-8"?>
 <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
   <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
     <security>
       <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
         <requestedExecutionLevel level="asInvoker" uiAccess="false" />
       </requestedPrivileges>
     </security>
   </trustInfo>
   <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
     <application>
     </application>
   </compatibility>
   <application xmlns="urn:schemas-microsoft-com:asm.v3">
     <windowsSettings>
       <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
         <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>
       <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
     </windowsSettings>
   </application>
 </assembly>

and my Windows 10 is Version 1809 (OS Build 17763.1999), with all those in project and 125% scaling in Monitor 1, this is what it does:

111336-test5.gif

windows-wpf
test4.gif (1.3 MiB)
test1.gif (1.4 MiB)
test2.gif (694.5 KiB)
test3.gif (2.1 MiB)
test5.gif (689.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered EmonHaque-1485 commented

Have you tried Per Monitor DPI ?


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Castorix31, tried that BUT doesn't work! See the EDIT part.

0 Votes 0 ·
EmonHaque-1485 avatar image
1 Vote"
EmonHaque-1485 answered EmonHaque-1485 edited

Tried with the following change in one of my views and it works:

     void refreshCommand() {
         if (BusyWindow.IsOpened) return;
         var dpi = VisualTreeHelper.GetDpi(this);
         var position = PointToScreen(new Point(0, 0));
         position.X /= dpi.DpiScaleX;
         position.Y /= dpi.DpiScaleY; 
         position.X += Constants.CardMargin.Left;
         position.Y += Constants.CardMargin.Top;
         var width = ActualWidth - Constants.CardMargin.Left - Constants.CardMargin.Right;
         var height = ActualHeight - Constants.CardMargin.Top - Constants.CardMargin.Bottom;       
         BusyWindow.Activate(position.X, position.Y, width, height, "Reloading ...");
         viewModel.Refresh.Invoke();
         BusyWindow.Terminate();
     }

So I have to divide x,y of PointToScreen by dpiscale, and with this I don't need App.Config/app.manifest. Not bad! Is there any better way?

EDIT


BUT this approach isn't pixel perfect! For example, with 100% and 125% scaling on these two Monitors:

111396-test6.gif

I see white stripes clearly on right in 2 leftmost views and the view in the middle on Monitor with 100% scaling. Those stripes shift to the left in 2 rightmost views :

111355-test7.gif

and on 125%, those stipes become subtle:

111401-test8.gif

Is it possible to make it pixel perfect?

Updated the RentManager without XAML ... in GitHub, you can download and test. Relevant code is in void refreshCommand() method in .cs files of Views\Home folder.


test7.gif (1.5 MiB)
test8.gif (1.2 MiB)
test6.gif (107.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.