Karthik R S
Karthik R S

Reputation: 45

How to obtain Windows Screen Resolution in UWP (XAML) App

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

Upvotes: 1

Views: 1160

Answers (1)

Jay Zuo
Jay Zuo

Reputation: 15758

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

Upvotes: 1

Related Questions