PicImageSourceConverter.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. namespace ivf_tl_Operate.Converts
  10. {
  11. public class PicImageSourceConverter : IMultiValueConverter
  12. {
  13. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. try
  16. {
  17. if (values.Count() != 2)
  18. {
  19. if (parameter.ToString() == "1")
  20. {
  21. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/LastEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  22. }
  23. else
  24. {
  25. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/NextEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  26. }
  27. }
  28. var a = values[0];
  29. var b = values[1];
  30. if (a == null || b == null)
  31. {
  32. if (parameter.ToString() == "1")
  33. {
  34. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/LastEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  35. }
  36. else
  37. {
  38. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/NextEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  39. }
  40. }
  41. int currentNum = int.Parse(a.ToString());
  42. int allNum = int.Parse(b.ToString());
  43. if (parameter.ToString() == "1")
  44. {
  45. if (currentNum > 0)
  46. {
  47. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/LastEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  48. }
  49. else
  50. {
  51. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/LastEmbryoDiscard.png", UriKind.RelativeOrAbsolute));
  52. }
  53. }
  54. else
  55. {
  56. if (currentNum < (allNum - 1))
  57. {
  58. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/NextEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  59. }
  60. else
  61. {
  62. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/NextEmbryoDiscard.png", UriKind.RelativeOrAbsolute));
  63. }
  64. }
  65. }
  66. catch (Exception)
  67. {
  68. if (parameter.ToString() == "1")
  69. {
  70. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/LastEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  71. }
  72. else
  73. {
  74. return new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Operate;component/Resources/Image/NextEmbryoUsable.png", UriKind.RelativeOrAbsolute));
  75. }
  76. }
  77. }
  78. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  79. {
  80. throw new NotImplementedException();
  81. }
  82. }
  83. }