CameraMountConverter.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. case CameraMount.MobileDown_IndependentXYPlatform:
  41. imageName = "MobileDown_IndependentXYPlatform.png";
  42. break;
  43. default:
  44. break;
  45. }
  46. // 返回图片资源的URI
  47. return new BitmapImage(new Uri($"/Resources/Images/{imageName}", UriKind.Relative));
  48. //return new BitmapImage(new Uri($"{imageName}"));
  49. }
  50. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  51. {
  52. return null;
  53. }
  54. }
  55. }