20

In Windows Phone 8 I can get the screen resolution using DeviceExtendedProperties or Application.Current.Host.Content.ScaleFactor. None of this works in Windows Phone 8.1 XAML.

I could not find a way how to get the screen resolution in Windows Phone 8.1 XAML, is there a way?

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118

2 Answers2

31

When using the WinRT API, you can retrieve the screen resolution with Windows.UI.Xaml.Window.Current.Bounds (Height and Width).

You need to multiply those values by the scale factor to get the real resolution. You can retrieve the scale factor by calling DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel

var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

Debug.WriteLine("The current resolution is {0}x{1}", Window.Current.Bounds.Width * scaleFactor, Window.Current.Bounds.Height * scaleFactor);
Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
  • 5.5" and 6" emulator's widths are both 1080p but when i run my app, 5.5" device renders differently. Is it same on real devices too? – garenyondem May 18 '15 at 08:13
  • @garenyondem most likely it is because they have different `RawPixelsPerViewPixel` factor, which defines your "soft resolution" measured in viewpixels (which is named in blend "effective device resolution"). Depending on the `RawPixelsPerViewPixel` value, which would prob. be in your case 220 or 240, you will get different "soft resolutions": 490x872 or 450x800, so if you have positioned element 50pixels off the right edge, it will appear in different location relative to center in different emulators, despite the resolution is the same. – Dimitry K Jul 07 '15 at 16:49
  • Also It seems that concept of `ScaleFactor` has changed in WP8.1 and has been "replaced" (kinda) with `RawPixelsPerViewPixel` concept... which would make sense unless this weird fact that sometimes for the same screen resolution this `RPPVP` can be different like I described above.. – Dimitry K Jul 07 '15 at 16:53
  • This is really great to get the actuall resolution. Thanks, Can you please provide some code how to get the Screen size in Inches i.e. 4", 4.5", 5" or 6" ... how to get this value. please – Zia Ur Rahman Aug 26 '17 at 07:01
10

You can get everything you need about the resolution using Window and DisplayInformation

var bounds = Window.Current.Bounds;
var displayInfo = DisplayInformation.GetForCurrentView();
yasen
  • 3,580
  • 13
  • 25
  • bounds return some strange values, as I mention in the comment to the previous answer. The displayInfo has na interesting scaling factor property, but it is 140 for WVGA and 180 for WXGA which does not seem right comparing to WP8 – Igor Kulman Jun 10 '14 at 20:08
  • 1
    @IgorKulman Sorry, I should've mentioned how to calculate it as well, and not just where to get the info that's needed. Anyway, I see KooKiz has already done that. :) – yasen Jun 10 '14 at 20:19