Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 12:06, 3 May 2013 by hamishwillee (Talk | contribs)

How to detect the screen resolution on Windows Phone

From Wiki
Jump to: navigation, search

This article explains how to detect the display resolution using reflection. The code can be used in Windows Phone 7 and later.

WP Metro Icon UI.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
SDK: Windows Phone SDK 8.0
Platform(s): Windows Phone 7 and later
Windows Phone 8
Windows Phone 7.5
Created: dan.ardelean (30 Apr 2013)
Last edited: hamishwillee (03 May 2013)



Windows Phone 7 apps can be run on Windows Phone 8 devices, and will usually display "acceptably" on the new display resolutions supported by Windows Phone 8. However if you want to take advantage of the new screen display resolutions, for example using higher quality images for higher resolution devices, you will need to know the ScaleFactor of the device.

The property is only available in the Windows Phone 8.0 SDK, but if you need to access it on a Windows Phone 7 app you can do so using reflection.


Retrieve the Get() method of the ScaleFactor property using reflection and invoke it only if the application is running on a Windows Phone 8 device.

public static Size DisplayResolution  
if (Environment.OSVersion.Version.Major<8)
return new Size(480,800);
int scaleFactor=(int) GetProperty(Application.Current.Host.Content, "ScaleFactor");
switch (scaleFactor)
case 100:
return new Size(480, 800);
case 150:
return new Size(720, 1280);
case 160:
return new Size(768, 1280);
return new Size(480, 800);
private static object GetProperty(object instance, string name)
var getMethod= instance.GetType().GetProperty(name).GetGetMethod();
return getMethod.Invoke(instance, null);

Test Code

The test code can be downloaded from here:

The Emulator output of the test code is shown below.



131 page views in the last 30 days.