private static void AddIconBindings(string iconName, string caption, Color color, params string[] elemTypes) { foreach (string elemType in elemTypes) { IconMetaData md = new IconMetaData(iconName, caption, color); _TaxaIconMetaData.Add(elemType, md); } }
public static ImageSource ConstructIcon(bool isAvailableOrLiteratureName, string elemType, bool isChanged) { // This is used to construct image uri's, if required... string assemblyName = typeof(TaxonViewModel).Assembly.GetName().Name; // Available and Literature names don'note have icons either if (isAvailableOrLiteratureName) { // Unless they've been changed, in which they get the if (isChanged) { return(ImageCache.GetImage(String.Format("pack://application:,,,/{0};component/images/ChangedOverlay.png", assemblyName))); } else { return(null); } } BitmapSource baseIcon = null; if (elemType == null) { return(null); } if (_ElemTypeIconCache.ContainsKey(elemType)) { baseIcon = _ElemTypeIconCache[elemType]; } if (baseIcon != null && !isChanged) { return(baseIcon); } if (baseIcon == null) { RenderTargetBitmap bmp = new RenderTargetBitmap(_IconSize, _IconSize, 96, 96, PixelFormats.Pbgra32); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext dc = drawingVisual.RenderOpen(); IconMetaData md = null; if (_TaxaIconMetaData.ContainsKey(elemType)) { md = _TaxaIconMetaData[elemType]; } Color taxonColor = (md == null ? Colors.Red : md.Color); string caption = (md == null ? "?" : md.Caption); Pen pen = new Pen(new SolidColorBrush(taxonColor), 2); Brush textBrush = new SolidColorBrush(Color.FromArgb(200, 0, 0, 0)); Brush fillBrush = new SolidColorBrush(Color.FromArgb(20, taxonColor.R, taxonColor.G, taxonColor.B)); Typeface typeface = new Typeface(new FontFamily("Palatino Linotype,Times New Roman"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); dc.DrawRoundedRectangle(fillBrush, pen, new Rect(1, 1, _IconSize - 2, _IconSize - 2), 4, 4); FormattedText t = new FormattedText(caption, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 10, textBrush); double originX = (bmp.Width / 2) - (t.Width / 2); double originY = (bmp.Height / 2) - (t.Height / 2); dc.DrawText(t, new Point(originX, originY)); dc.Close(); bmp.Render(drawingVisual); if (elemType != null && !_ElemTypeIconCache.ContainsKey(elemType)) { _ElemTypeIconCache.Add(elemType, bmp); } baseIcon = bmp; } if (isChanged) { return(ImageCache.ApplyOverlay(baseIcon, String.Format("pack://application:,,,/{0};component/images/ChangedOverlay.png", assemblyName))); } return(baseIcon); }