0

When i'm trying to get actual resolution with on my 4K resolution:

Screen.PrimaryScreen.Bounds.Width

Or:

System.Windows.SystemParameters.PrimaryScreenWidth

It will show resolution 2560x1440. It is weird it a few times show right resolution 3840x2160. But I don't know how it is possible.

  • 1
    See http://stackoverflow.com/questions/2236173/screen-resolution-problem-in-wpf WPF keep units depending on the DPI of the display adapter and not pixels. – Jay Mar 18 '16 at 16:29

1 Answers1

0

The problem is because windows tries to render applications that do not have any dpi management. So windows pretends that it is running the application on another resolution. if you are using windows OS with major version greater than 6.0, you can use the following function:

private enum ProcessDPIAwareness
{
        ProcessDPIUnaware = 0,
        ProcessSystemDPIAware = 1,
        ProcessPerMonitorDPIAware = 2
}

    [DllImport("shcore.dll")]
    private static extern int SetProcessDpiAwareness(ProcessDPIAwareness value);



    private static void SetDpiAwareness()
        {
           if (Environment.OSVersion.Version.Major >= 6)
                 {
                       SetProcessDpiAwareness(ProcessDPIAwareness.ProcessPerMonitorDPIAware);
                 }
         }
hrkad
  • 105
  • 8