Skip to content

Instantly share code, notes, and snippets.

@martinsuchan
Created January 21, 2016 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinsuchan/8d6db4fd4d0ad6c1b606 to your computer and use it in GitHub Desktop.
Save martinsuchan/8d6db4fd4d0ad6c1b606 to your computer and use it in GitHub Desktop.
Lumia 950 and 950 XL screen size detection on WP8.1 Silverlight
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using Microsoft.Phone.Info;
namespace PhoneApp1
{
public class ScreenSizeHelper
{
public static double GetScaleFactor()
{
// Lumia 950 and 950 XL always returns wrong ScaleFactor 160
return IsWqhdDevice() ? 320 : Application.Current.Host.Content.ScaleFactor;
}
public static Size GetPhysicalScreenResolution()
{
// Lumia 950 and 950 XL always returns wrong Size 768x1280
if (IsWqhdDevice()) return new Size(1440, 2560);
try
{
Size size = (Size)DeviceExtendedProperties.GetValue("PhysicalScreenResolution");
return size;
}
catch (Exception e)
{
Debug.WriteLine("Error getting PhysicalScreenResolution {0}", e);
return new Size(480, 800);
}
}
// all device codes for Lumia 950 and Lumia 950 XL
private static readonly string[] wqhdDevices = { "rm-1104", "rm-1105", "rm-1118", "rm-1085", "rm-1116" };
private static bool? isWqhdDevice;
public static bool IsWqhdDevice()
{
if (!isWqhdDevice.HasValue)
{
string deviceName = DeviceStatus.DeviceName.ToLower();
isWqhdDevice = wqhdDevices.Any(d => deviceName.Contains(d));
}
return isWqhdDevice.Value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment