BoolMutiConverter.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Data;
  7. using Aitex.Core.RT.Log;
  8. namespace MECF.Framework.UI.Core.Converters
  9. {
  10. public class BoolAndMutiConverter : IMultiValueConverter
  11. {
  12. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if (values.Length == 0) return false;
  15. try
  16. {
  17. bool r = true;
  18. for (int ii = 0; ii < values.Length; ii++)
  19. {
  20. bool b = (bool)values[ii];
  21. if (!b) { r = false; break; }
  22. }
  23. return r;
  24. }
  25. catch (Exception ex)
  26. {
  27. LOG.Write(ex);
  28. }
  29. return false;
  30. }
  31. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  32. {
  33. return null;
  34. }
  35. }
  36. public class BoolOrMutiConverter : IMultiValueConverter
  37. {
  38. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  39. {
  40. if (values.Length == 0) return false;
  41. try
  42. {
  43. bool r = false;
  44. for (int ii = 0; ii < values.Length; ii++)
  45. {
  46. bool b = (bool)values[ii];
  47. if (b) { r = true; break; }
  48. }
  49. return r;
  50. }
  51. catch (Exception ex)
  52. {
  53. LOG.Write(ex);
  54. }
  55. return false;
  56. }
  57. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  58. {
  59. return null;
  60. }
  61. }
  62. public class BoolAnd2VisibilityMutiConverter : IMultiValueConverter
  63. {
  64. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  65. {
  66. if (values.Length == 0) return false;
  67. try
  68. {
  69. Visibility r = Visibility.Visible;
  70. for (int ii = 0; ii < values.Length; ii++)
  71. {
  72. bool b = (bool)values[ii];
  73. if (!b) { r = Visibility.Collapsed; break; }
  74. }
  75. return r;
  76. }
  77. catch (Exception ex)
  78. {
  79. LOG.Write(ex);
  80. }
  81. return Visibility.Collapsed;
  82. }
  83. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  84. {
  85. return null;
  86. }
  87. }
  88. public class BoolOr2VisibilityMutiConverter : IMultiValueConverter
  89. {
  90. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  91. {
  92. if (values.Length == 0) return false;
  93. try
  94. {
  95. Visibility r = Visibility.Collapsed;
  96. for (int ii = 0; ii < values.Length; ii++)
  97. {
  98. bool b = (bool)values[ii];
  99. if (b) { r = Visibility.Visible; break; }
  100. }
  101. return r;
  102. }
  103. catch (Exception ex)
  104. {
  105. LOG.Write(ex);
  106. }
  107. return Visibility.Collapsed;
  108. }
  109. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  110. {
  111. return null;
  112. }
  113. }
  114. }