Created
July 25, 2014 18:53
-
-
Save dgkanatsios/7ed78e3ca990e978ac23 to your computer and use it in GitHub Desktop.
Resolution helpers for Windows Phone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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