1

In order to get the actual resolution of the PC, we are using

var displayInformation = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();

The above instance has two properties

  1. ScreenHeightInRawPixels
  2. ScreenWidthInRawPixels

With the above two properties we can get the screen resolution.

This works fine in the case of a regular desktop, but when we execute the same code on a surface we are getting null values for the above two properties.

Ask: we need the System Resolution, not the app resolution. i.e. even when the app is not maximized to full screen, we need the screen resolution of the entire PC.

Platform : Windows 10 UWP XAML

Kindly help us in this aspect.

Thanks, Karthik

Bells
  • 1,465
  • 1
  • 19
  • 30
  • This? http://stackoverflow.com/questions/31936154/get-screen-resolution-in-win10-uwp-app – Fırat Esmer Mar 01 '17 at 20:10
  • Thanks for the reply. We need the height and Width of the Screen not the App. We can find the properties ScreenHeightInRawPixels, ScreenWidthInRawPixels , but the values seems to be null only for surface. (invalid Cast expection) Detail Error Message: Message "Unable to cast object of type 'Windows.Graphics.Display.DisplayInformation' to type 'Windows.Graphics.Display.IDisplayInformation4'." string – Karthik R S Mar 02 '17 at 13:52

1 Answers1

1

ScreenHeightInRawPixels and ScreenWidthInRawPixels property should be able to work on Surface. However please note they are newly added in Windows 10 Anniversary Update (aka RS1 Update).

To use these two properties please make sure your project targets Windows 10 Anniversary Edition or later. You can check the Target Version in Properties like in the following screenshot.
enter image description here

Besides, you may also need to check the OS version of your Surface and make sure the OS Build is 14393 or later. You can find the OS Build in "Setting""System""About".
enter image description here

Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • Thanks for the quick reply. If the user doesn't have14393 build this might cause a problem. Is there any other way to obtain the Screen Height and Width, so that it would be backward compatible with older versions as well. Thanks Karthik – Karthik R S Mar 03 '17 at 14:25
  • @KarthikRS: For backward compatible, you can refer to [this answer](http://stackoverflow.com/a/31937161/5506161) and also [How to Get Screen Resolution in Win10 UWP App](https://code.msdn.microsoft.com/windowsapps/How-to-Get-Screen-563bc790). But please note **this method might not work while your project targets Build 14393 or later.** – Jay Zuo Mar 06 '17 at 10:51
  • For projects target Build 14393 or later, `ScreenHeightInRawPixels` and `ScreenWidthInRawPixels` property are always recommended. And we can use [ApiInformation.IsPropertyPresent](https://learn.microsoft.com/en-us/uwp/api/windows.foundation.metadata.apiinformation#Windows_Foundation_Metadata_ApiInformation_IsPropertyPresent_System_String_System_String_) to detect if `ScreenHeightInRawPixels` or `ScreenWidthInRawPixels` property is present. If they are not present, we can then use the traditional method. – Jay Zuo Mar 06 '17 at 11:14
  • Thanks for the quick reply. Can you just brief us on the traditional method. – Karthik R S Mar 07 '17 at 15:07
  • @KarthikRS For traditional method, you can refer to [this answer](http://stackoverflow.com/a/31937161/5506161) and also [How to Get Screen Resolution in Win10 UWP App](https://code.msdn.microsoft.com/windowsapps/How-to-Get-Screen-563bc790). – Jay Zuo Mar 08 '17 at 06:32