public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return null; try { if (value is string) { var path = (string)value; var ext = Path.GetExtension(path); if (string.IsNullOrWhiteSpace(ext)) return null; BitmapSource icon; if (!_icon.TryGetValue(ext, out icon)) { icon = IconUtilities.FileAssociatedImage(ext, false, false); if (icon.CanFreeze) icon.Freeze(); _icon[ext] = icon; } return icon; } else if (value is Seed) { Seed seed = (Seed)value; if (string.IsNullOrWhiteSpace(seed.Name)) return null; var ext = Path.GetExtension(seed.Name); if (string.IsNullOrWhiteSpace(ext)) return null; BitmapSource icon; if (!_icon.TryGetValue(ext, out icon)) { icon = IconUtilities.FileAssociatedImage(ext, false, false); if (icon.CanFreeze) icon.Freeze(); _icon[ext] = icon; } return icon; } else if (value is Box) { return _boxIcon; } } catch (Exception) { } return null; }
static ObjectToImageConverter() { var ext = ".box"; var icon = IconUtilities.FileAssociatedImage(ext, false, false); if (icon.CanFreeze) icon.Freeze(); _boxIcon = icon; }