BoxToDescriptionConverter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Markup;
  6. using System.Windows.Data;
  7. using MatrixIO.IO.Bmff;
  8. using MatrixIO.IO.Bmff.Boxes;
  9. namespace BmffViewer
  10. {
  11. public class BoxToDescriptionConverter : MarkupExtension, IValueConverter
  12. {
  13. public BoxToDescriptionConverter() : base() { }
  14. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  15. {
  16. if (value is UnknownBox) return "Unknown Box Type";
  17. else if (value is Box)
  18. {
  19. // TODO: This may have to change for Sample Description Box ('stsd') children.
  20. object[] boxAttributes = value.GetType().GetCustomAttributes(typeof(BoxAttribute), true);
  21. foreach (BoxAttribute boxAttribute in boxAttributes)
  22. if (((Box)value).Type == boxAttribute.Type) return boxAttribute.Description;
  23. // The BoxType doesn't match any of the BoxAttributes associated with this object. Eek!
  24. return "Badly Defined Box Type";
  25. }
  26. else return "";
  27. }
  28. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  29. {
  30. return null;
  31. }
  32. public override object ProvideValue(IServiceProvider serviceProvider)
  33. {
  34. return this;
  35. }
  36. }
  37. }