Skip to content

Instantly share code, notes, and snippets.

@dgkanatsios
Created July 25, 2014 18:53
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 dgkanatsios/7ed78e3ca990e978ac23 to your computer and use it in GitHub Desktop.
Save dgkanatsios/7ed78e3ca990e978ac23 to your computer and use it in GitHub Desktop.
Resolution helpers for Windows Phone
public static class ResolutionHelper
{
public static Uri GetScaledImageUri(String imageName)
{
int scaleFactor = (int)Application.Current.Host.Content.ScaleFactor;
switch (scaleFactor)
{
case 100: return new Uri(imageName + "_wvga.png", UriKind.RelativeOrAbsolute);
case 150: return new Uri(imageName + "_720p.png", UriKind.RelativeOrAbsolute);
case 160: return new Uri(imageName + "_wxga.png", UriKind.RelativeOrAbsolute);
default: throw new InvalidOperationException("Unknown resolution type");
}
}
public static string GetResolutionString()
{
int scaleFactor = (int)Application.Current.Host.Content.ScaleFactor;
switch (scaleFactor)
{
case 100: return "wxga"; //should return wvga
case 150: return "720p";
case 160: return "wxga";
default: throw new InvalidOperationException("Unknown resolution type");
}
}
public static bool IsWvga
{
get
{
return Application.Current.Host.Content.ScaleFactor == 100;
}
}
public static bool IsWxga
{
get
{
return Application.Current.Host.Content.ScaleFactor == 160;
}
}
public static bool Is720p
{
get
{
return Application.Current.Host.Content.ScaleFactor == 150;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment