PickPlaceModelConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.Data;
  8. using System.Windows.Media.Imaging;
  9. using TeamAAS_VP.Enums;
  10. namespace TeamAAS_VP.ValueConverter
  11. {
  12. public class PickPlaceModelConverter : IValueConverter
  13. {
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. if (value == null || !(value is PickPlaceModel))
  17. return null;
  18. PickPlaceModel enumValue = (PickPlaceModel)value;
  19. string imageName = string.Empty;
  20. // 根据枚举值选择对应的图片资源名称
  21. switch (enumValue)
  22. {
  23. case PickPlaceModel.Inhal:
  24. imageName = "Inhal.png";
  25. break;
  26. case PickPlaceModel.Clamp:
  27. imageName = "Clamp.png";
  28. break;
  29. default:
  30. break;
  31. }
  32. // 返回图片资源的URI
  33. return new BitmapImage(new Uri($"/Resources/Images/{imageName}", UriKind.Relative));
  34. //return new BitmapImage(new Uri($"{imageName}"));
  35. }
  36. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  37. {
  38. return null;
  39. }
  40. }
  41. }