ModelCheckConverter.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* ==============================================================================
  2. * 功能描述:ModelCheckConverter
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/10/21 16:02:55
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.ObjectModel;
  8. using System.Globalization;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Media.Imaging;
  15. namespace Saga.PlugIn.ModelCheck
  16. {
  17. /// <summary>
  18. /// ModelCheckConverter
  19. /// </summary>
  20. class ItemImageVisibleConverter : IValueConverter
  21. {
  22. public bool IsEqualCollapsed { get; set; }
  23. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  24. {
  25. var state = (ModelCheckState) value;
  26. Visibility visibility = Visibility.Visible;
  27. if (IsEqualCollapsed)
  28. {
  29. visibility = (state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible);
  30. }
  31. else
  32. {
  33. visibility = (!state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible);
  34. }
  35. return visibility;
  36. }
  37. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  38. {
  39. throw new NotImplementedException();
  40. }
  41. }
  42. class ItemImageConverter : IMultiValueConverter
  43. {
  44. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  45. {
  46. var items = value as ObservableCollection<ModeCheckResultBase>;
  47. BitmapSource image = null;
  48. string imageName = null;
  49. if (items != null &&items.Count>0&& items.All(t => t.IsRight))
  50. {
  51. imageName = "对勾.png";
  52. }
  53. else
  54. {
  55. imageName = "叉.png";
  56. }
  57. if (!string.IsNullOrEmpty(imageName))
  58. {
  59. Uri uri = new Uri("pack://application:,,,/Saga.PlugIn;component/ModelCheck/Image/" + imageName);
  60. image= BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
  61. }
  62. return image;
  63. }
  64. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  65. {
  66. throw new NotImplementedException();
  67. }
  68. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  69. {
  70. var state = (ModelCheckState)values[0];
  71. BitmapSource image = null;
  72. string imageName = null;
  73. if(state== ModelCheckState.Progress)
  74. imageName = "省略号.png";
  75. else
  76. {
  77. var items = values[1] as ObservableCollection<ModeCheckResultBase>;
  78. if (items != null && items.All(t => t.IsRight))
  79. {
  80. imageName = "对勾.png";
  81. }
  82. else
  83. {
  84. imageName = "叉.png";
  85. }
  86. }
  87. if (!string.IsNullOrEmpty(imageName))
  88. {
  89. Uri uri = new Uri("pack://application:,,,/Saga.PlugIn;component/ModelCheck/Image/" + imageName);
  90. image = BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
  91. }
  92. return image;
  93. }
  94. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  95. {
  96. throw new NotImplementedException();
  97. }
  98. }
  99. }