SmartViewConverters.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. using System.Windows;
  8. using Aitex.Core.RT.Log;
  9. namespace Aitex.Smart.UI.Converters
  10. {
  11. public class LineColorConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  14. {
  15. try
  16. {
  17. Color color = (Color)value;
  18. return new SolidColorBrush(color);
  19. }
  20. catch (Exception ex)
  21. {
  22. LOG.Write(ex);
  23. }
  24. return Brushes.Black;
  25. }
  26. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  27. {
  28. try
  29. {
  30. Brush brush = (SolidColorBrush)value;
  31. Color color = (Color)ColorConverter.ConvertFromString(brush.ToString());
  32. return color;
  33. }
  34. catch (Exception ex)
  35. {
  36. LOG.Write(ex);
  37. }
  38. return Colors.Black;
  39. }
  40. }
  41. public class bool2VisibilityConverter : IValueConverter
  42. {
  43. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  44. {
  45. try
  46. {
  47. if ((bool)value)
  48. return Visibility.Visible;
  49. return Visibility.Hidden;
  50. }
  51. catch (Exception ex)
  52. {
  53. LOG.Write(ex);
  54. }
  55. return Visibility.Hidden;
  56. }
  57. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  58. {
  59. return null;
  60. }
  61. }
  62. public class Visibility2boolConverter : IValueConverter
  63. {
  64. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  65. {
  66. try
  67. {
  68. Visibility vi = (Visibility)value;
  69. if (vi == Visibility.Visible) return true;
  70. return false;
  71. }
  72. catch (Exception ex)
  73. {
  74. LOG.Write(ex);
  75. }
  76. return true;
  77. }
  78. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  79. {
  80. try
  81. {
  82. bool isChecked = (bool)value;
  83. if (isChecked) return Visibility.Visible;
  84. return Visibility.Hidden;
  85. }
  86. catch (Exception ex)
  87. {
  88. LOG.Write(ex);
  89. }
  90. return Visibility.Visible;
  91. }
  92. }
  93. public class RolloverDataTimeConverter : IValueConverter
  94. {
  95. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  96. {
  97. if (value != null)
  98. {
  99. DateTime dt;
  100. var isSucc = DateTime.TryParse(value.ToString(), out dt);
  101. if (isSucc)
  102. return string.Format("{0}{1}{2}", " 【", dt.ToString("yyyy/MM/dd HH:mm:ss"), "】 ");
  103. }
  104. return "N/A";
  105. }
  106. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  107. {
  108. return null;
  109. }
  110. }
  111. public class ColorToBrushConverter : IValueConverter
  112. {
  113. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  114. {
  115. try
  116. {
  117. var color = (System.Windows.Media.Color)value;
  118. return new System.Windows.Media.SolidColorBrush(color);
  119. }
  120. catch (Exception ex)
  121. {
  122. LOG.Write(ex);
  123. }
  124. return System.Windows.Media.Brushes.Black;
  125. }
  126. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  127. {
  128. return null;
  129. }
  130. }
  131. public class RolloverDataPointerInfoConverter : IMultiValueConverter
  132. {
  133. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  134. {
  135. try
  136. {
  137. DateTime time = (DateTime)values[0];
  138. double y = (double)values[1];
  139. return string.Format("【{0}】 {1}", time.ToString("yyyy/MM/dd HH:mm:ss"), y);
  140. }
  141. catch (Exception ex)
  142. {
  143. LOG.Write(ex);
  144. }
  145. return "";
  146. }
  147. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  148. {
  149. return null;
  150. }
  151. }
  152. public class RadioBoolToIntConverter : IValueConverter
  153. {
  154. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  155. {
  156. int integer = (int)value;
  157. if (integer == int.Parse(parameter.ToString()))
  158. return true;
  159. else
  160. return false;
  161. }
  162. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  163. {
  164. return parameter;
  165. }
  166. }
  167. }