IsMultiSavedColorConverter.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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;
  9. namespace FurnaceUI.Converter
  10. {
  11. public class IsMultiSavedConverter : IMultiValueConverter
  12. {
  13. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (values.Length == 2)
  16. {
  17. if (values[0] is string)
  18. {
  19. double tempValue = double.NaN;
  20. double.TryParse((string)values[0], out tempValue);
  21. if (tempValue != double.NaN && Math.Abs(tempValue) < 0.000001)
  22. { return true; }
  23. else
  24. {
  25. if (values[1] is bool)
  26. {
  27. if ((bool)values[1])
  28. return true;
  29. else
  30. return false;
  31. }
  32. }
  33. }
  34. if (values[1] is bool)
  35. {
  36. if ((bool)values[1])
  37. return true;
  38. else
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. }
  49. public class IsMultiSavedColorConverter : IMultiValueConverter
  50. {
  51. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  52. {
  53. if (values.Length == 2)
  54. {
  55. if (values[0] is string)
  56. {
  57. double tempValue = double.NaN;
  58. double.TryParse((string)values[0], out tempValue);
  59. if (tempValue != double.NaN && Math.Abs(tempValue) < 0.000001)
  60. { return new SolidColorBrush(Colors.Transparent); }
  61. else
  62. {
  63. if (values[1] is bool)
  64. {
  65. if ((bool)values[1])
  66. return new SolidColorBrush(Colors.Transparent);
  67. else
  68. return new SolidColorBrush(Colors.Yellow);
  69. }
  70. }
  71. }
  72. if (values[1] is bool)
  73. {
  74. if ((bool)values[1])
  75. return new SolidColorBrush(Colors.Transparent);
  76. else
  77. return new SolidColorBrush(Colors.Yellow);
  78. }
  79. }
  80. return new SolidColorBrush(Colors.Transparent);
  81. }
  82. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  83. {
  84. throw new NotImplementedException();
  85. }
  86. }
  87. }