Created
July 14, 2013 09:19
-
-
Save damirarh/5993727 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 class EnumToImageConverter : IValueConverter | |
{ | |
public string SubFolder { get; set; } | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
if (value is Enum && targetType == typeof(ImageSource)) | |
{ | |
var enumType = value.GetType(); | |
var format = String.IsNullOrEmpty(SubFolder) ? "/Assets/{0}/{2}.png" : "/Assets/{0}/{1}/{2}.png"; | |
var path = String.Format(format, enumType.Name, SubFolder, Enum.GetName(enumType, value)); | |
var uri = new Uri(path, UriKind.Relative); | |
return new BitmapImage(uri); | |
} | |
return value; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment