ModelCheckConverter.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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[] values, Type targetType, object parameter, CultureInfo culture)
  45. {
  46. var state = (ModelCheckState)values[0];
  47. BitmapSource image = null;
  48. string imageName = null;
  49. if(state== ModelCheckState.Progress)
  50. imageName = "等待.png";
  51. else
  52. {
  53. var items = values[1] as ObservableCollection<ModeCheckResultBase>;
  54. if (items != null && items.All(t => t.IsRight))
  55. {
  56. imageName = "正确.png";
  57. }
  58. else
  59. {
  60. imageName = "错误.png";
  61. }
  62. }
  63. if (!string.IsNullOrEmpty(imageName))
  64. {
  65. Uri uri = new Uri("pack://application:,,,/Saga.PlugIn;component/ModelCheck/Image/" + imageName);
  66. image = BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
  67. }
  68. return image;
  69. }
  70. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. }
  75. }