CameraMountConverter.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Imaging;
  11. using TeamAAS_VP.Enums;
  12. namespace TeamAAS_VP.ValueConverter
  13. {
  14. public class CameraMountConverter : IValueConverter
  15. {
  16. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. if (value == null || !(value is CameraMount))
  19. return null;
  20. CameraMount enumValue = (CameraMount)value;
  21. string imageName = string.Empty;
  22. // 根据枚举值选择对应的图片资源名称
  23. switch (enumValue)
  24. {
  25. case CameraMount.FixedUp:
  26. imageName = "FixedUp.jpg";
  27. break;
  28. case CameraMount.FixedDown:
  29. imageName = "FixedDown.jpg";
  30. break;
  31. case CameraMount.MobileJ2:
  32. imageName = "MobileJ2.jpg";
  33. break;
  34. case CameraMount.MobileJ4:
  35. imageName = "MobileJ4.jpg";
  36. break;
  37. case CameraMount.MobileDown_XYPlatform:
  38. imageName = "MobileDown.png";
  39. break;
  40. default:
  41. break;
  42. }
  43. // 返回图片资源的URI
  44. return new BitmapImage(new Uri($"/Resources/Images/{imageName}", UriKind.Relative));
  45. //return new BitmapImage(new Uri($"{imageName}"));
  46. }
  47. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  48. {
  49. return null;
  50. }
  51. }
  52. }