/// <summary> /// This function does the actual conversion from enum to <seealso cref="BitmapImage"/>. /// </summary> /// <param name="image"></param> /// <returns></returns> public BitmapImage SetImageSource(MsgBoxImage image) { BitmapImage ret = null; switch (image) { case MsgBoxImage.Information: ret = this.GetApplicationResource("MsgBoxImage_Information"); break; case MsgBoxImage.Question: ret = this.GetApplicationResource("MsgBoxImage_Question"); break; case MsgBoxImage.Error: ret = this.GetApplicationResource("MsgBoxImage_Error"); break; case MsgBoxImage.OK: ret = this.GetApplicationResource("MsgBoxImage_OK"); break; case MsgBoxImage.Alert: ret = this.GetApplicationResource("MsgBoxImage_Alert"); break; case MsgBoxImage.Default: ret = this.GetApplicationResource("MsgBoxImage_Default"); break; case MsgBoxImage.Warning: ret = this.GetApplicationResource("MsgBoxImage_Warning"); break; case MsgBoxImage.Default_OffLight: ret = this.GetApplicationResource("MsgBoxImage_Default_OffLight"); break; case MsgBoxImage.Default_RedLight: ret = this.GetApplicationResource("MsgBoxImage_Default_RedLight"); break; case MsgBoxImage.Information_Orange: ret = this.GetApplicationResource("MsgBoxImage_Information_Orange"); break; case MsgBoxImage.Information_Red: ret = this.GetApplicationResource("MsgBoxImage_Information_Red"); break; case MsgBoxImage.Process_Stop: ret = this.GetApplicationResource("MsgBoxImage_Process_Stop"); break; case MsgBoxImage.None: return(null); default: throw new NotImplementedException(image.ToString()); } // just return dynamic resource if we found one // otherwise fall-through here and return back up image if (ret != null) { return(ret); } string resourceAssembly = Assembly.GetAssembly(typeof(MsgBoxViewModel)).GetName().Name; string folder = "MsgBox/Images/MsgBoxImages/"; // Tango Icon set: http://commons.wikimedia.org/wiki/Tango_icons // Default image displayed in message box string source = string.Format("pack://application:,,,/{0};component/{1}48px-Dialog-information_on.svg.png", resourceAssembly, folder); try { source = string.Format("pack://application:,,,/{0};component/{1}{2}", resourceAssembly, folder, ImageEnumToImageConverter.msgBoxImageResourcesUris[(int)image]); } catch (Exception) { } Uri imageUri = new Uri(source, UriKind.RelativeOrAbsolute); return(new BitmapImage(imageUri)); }