Saturday, December 29, 2012

How to determine screen resolution on Windows Phone 8

This is a very common scenario most developers stumble across - they are building an app for Windows Phone and have to target all 3 screen resolutions available with Windows Phone 8.

The 3 screen resolutions for your reference are:

WVGA - 480x800 or 800x480 (15:9 ratio)
WXGA - 768x1280 or 1280x768 (15:9 ratio)
720p - 720x1280 or 1280x720 (16:9 ratio)

There may be many scenarios in which you would want to know the screen resolution of the device your app is running on, a popular one being that you want to show higher quality images for higher resolution devices. You can accomplish this very easily by checking for the ScaleFactor as follows:

if(App.Current.Host.Content.ScaleFactor == 100)
  // WVGA
else if (App.Current.Host.Content.ScaleFactor == 160)
  // WXGA
else if (App.Current.Host.Content.ScaleFactor == 150)
  // 720p

And that is all there is to it. Happy Coding!

Until next time,
Paras Wadehra
(Nokia Developer Ambassador)
Twitter: @ParasWadehra

1 comment:

Paras Wadehra said...

Thanks Lee; I am glad you found this blog post helpful.