BoxToIconConverter.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Windows.Markup;
  7. using System.Reflection;
  8. using MatrixIO.IO.Bmff.Boxes;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using MatrixIO.IO.Bmff;
  13. using System.Windows.Interop;
  14. using System.Drawing;
  15. using System.Windows;
  16. namespace BmffViewer
  17. {
  18. public class BoxToIconConverter : MarkupExtension, IValueConverter
  19. {
  20. public BoxToIconConverter() : base() { }
  21. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  22. {
  23. if (value is BaseMediaFile) return GetFileIcon(((BaseMediaFile)value).FullName);
  24. if (value is UnknownBox) return new BitmapImage(new Uri("pack://application:,,,/BmffViewer;component/Images/109_AllAnnotations_Warning_16x16_72.png"));
  25. if(value is ISuperBox) return new BitmapImage(new Uri("pack://application:,,,/BmffViewer;component/Images/Folder_16x16.png"));
  26. return new BitmapImage(new Uri("pack://application:,,,/BmffViewer;component/Images/EntityDataModel_ComplexTypeProperty_16x16.png"));
  27. }
  28. private ImageSource GetFileIcon(string filename)
  29. {
  30. using (Icon i = Icon.ExtractAssociatedIcon(filename))
  31. {
  32. return Imaging.CreateBitmapSourceFromHIcon(
  33. i.Handle,
  34. new Int32Rect(0, 0, i.Width, i.Height),
  35. BitmapSizeOptions.FromEmptyOptions());
  36. }
  37. }
  38. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  39. {
  40. return null;
  41. }
  42. public override object ProvideValue(IServiceProvider serviceProvider)
  43. {
  44. return this;
  45. }
  46. }
  47. }