FileExtensionToImageSourceConverter.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. namespace PixiEditor.Helpers.Converters
  10. {
  11. public class FileExtensionToImageSourceConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. string extension = (string)value;
  16. if (extension == ".pixi")
  17. {
  18. return Join("PixiFile.png", parameter);
  19. }
  20. else if (extension == ".png")
  21. {
  22. return Join("PngFile.png", parameter);
  23. }
  24. else if (extension == ".jpg" || extension == ".jpeg")
  25. {
  26. return Join("JpgFile.png", parameter);
  27. }
  28. return Join("UnknownFile.png", parameter);
  29. }
  30. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  31. {
  32. throw new NotImplementedException();
  33. }
  34. private string Join(string path, object parameter)
  35. {
  36. return Path.Join((string)parameter, "Images", path);
  37. }
  38. }
  39. }