ModelCheckConverter.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* ==============================================================================
  2. * 功能描述:ModelCheckConverter
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/10/21 16:02:55
  5. * ==============================================================================*/
  6. using System;
  7. using System.Globalization;
  8. using System.Text;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Media.Imaging;
  13. namespace Saga.PlugIn.ModelCheck
  14. {
  15. /// <summary>
  16. /// ModelCheckConverter
  17. /// </summary>
  18. class ItemImageVisibleConverter : IValueConverter
  19. {
  20. public bool IsEqualCollapsed { get; set; }
  21. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  22. {
  23. var state = (ModelCheckState) value;
  24. Visibility visibility = Visibility.Visible;
  25. if (IsEqualCollapsed)
  26. {
  27. visibility = (state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible);
  28. }
  29. else
  30. {
  31. visibility = (!state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible);
  32. }
  33. return visibility;
  34. }
  35. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  36. {
  37. throw new NotImplementedException();
  38. }
  39. }
  40. class ItemImageConverter : IValueConverter
  41. {
  42. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  43. {
  44. var state = (ModelCheckState)value;
  45. BitmapSource image = null;
  46. string imageName = null;
  47. switch (state)
  48. {
  49. case ModelCheckState.Progress:
  50. imageName = "省略号.png";
  51. break;
  52. case ModelCheckState.Ending:
  53. imageName = "对勾.png";
  54. break;
  55. }
  56. if (!string.IsNullOrEmpty(imageName))
  57. {
  58. Uri uri = new Uri("pack://application:,,,/Saga.PlugIn;component/ModelCheck/Image/" + imageName);
  59. image= BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
  60. }
  61. return image;
  62. }
  63. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. }
  68. }