I have an enum with each value representing an image, for example:
public enum AnimalImages
{
Cow,
Cat,
Dog
}
I also have a converter that takes the enum and returns an ImageSource:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ResourceManager.Instance.GetImageFromEnum((AnimalImages)value);
}
I am using WPF with MVVM; now, I want to add an image to my view. Using the Cow
enum, I would like the cow image. I know that I can add a property to my ViewModel and call it like this:
public AnimalImages CowImage
{
return AnimalImages.Cow;
}
and then bind it to my UI. But, I'm thinking there is a better way of doing this. Something like the following (which doesn't work of course):
<Image Source="{x:Static images:AnimalImages.Cow}, Converter={StaticResource AnimalImagesImageBitmapSource}}"/>
any suggestions?