IntToVisibilityConvert.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. namespace ivf_tl_Manage.Converts
  12. {
  13. public class Int_1ToHiddenConvert : IValueConverter
  14. {
  15. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. if (value != null && value.ToString() == "-1")
  18. {
  19. return Visibility.Hidden;
  20. }
  21. else
  22. {
  23. return Visibility.Visible;
  24. }
  25. }
  26. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  27. {
  28. throw new NotImplementedException();
  29. }
  30. }
  31. public class Int_1ToVisibleConvert : IValueConverter
  32. {
  33. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  34. {
  35. if (value != null && value.ToString() == "-1")
  36. {
  37. return Visibility.Visible;
  38. }
  39. else
  40. {
  41. return Visibility.Hidden;
  42. }
  43. }
  44. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. }
  49. public class Int0ToHiddenConvert : IValueConverter
  50. {
  51. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  52. {
  53. if (value != null && value.ToString() == "0")
  54. {
  55. return Visibility.Hidden;
  56. }
  57. else
  58. {
  59. return Visibility.Visible;
  60. }
  61. }
  62. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. }
  67. public class Int0ToCollapsedConvert : IValueConverter
  68. {
  69. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  70. {
  71. if (value != null && value.ToString() == "0")
  72. {
  73. return Visibility.Collapsed;
  74. }
  75. else
  76. {
  77. return Visibility.Visible;
  78. }
  79. }
  80. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. }
  85. public class Int1ToVisibilityConvert : IValueConverter
  86. {
  87. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  88. {
  89. if (value != null && value.ToString() == "1")
  90. {
  91. return Visibility.Visible;
  92. }
  93. else
  94. {
  95. return Visibility.Hidden;
  96. }
  97. }
  98. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  99. {
  100. throw new NotImplementedException();
  101. }
  102. }
  103. public class Int2ToDownVisibilityConvert : IValueConverter
  104. {
  105. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  106. {
  107. if (value != null && value.ToString() == "2")
  108. {
  109. return Visibility.Visible;
  110. }
  111. else
  112. {
  113. return Visibility.Collapsed;
  114. }
  115. }
  116. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  117. {
  118. throw new NotImplementedException();
  119. }
  120. }
  121. public class Int1ToHiddenConvert : IValueConverter
  122. {
  123. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  124. {
  125. if (value != null && value.ToString() == "1")
  126. {
  127. return Visibility.Hidden;
  128. }
  129. else
  130. {
  131. return Visibility.Visible;
  132. }
  133. }
  134. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  135. {
  136. throw new NotImplementedException();
  137. }
  138. }
  139. public class Int0ToVisibilityConvert : IValueConverter
  140. {
  141. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  142. {
  143. if (value != null && value.ToString() == "0")
  144. {
  145. return Visibility.Visible;
  146. }
  147. else
  148. {
  149. return Visibility.Hidden;
  150. }
  151. }
  152. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  153. {
  154. throw new NotImplementedException();
  155. }
  156. }
  157. public class Int2ToVisibilityConvert : IValueConverter
  158. {
  159. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  160. {
  161. if (value != null)
  162. {
  163. ICollection collection = value as ICollection;
  164. if (collection != null && collection.Count > 0) return Visibility.Visible;
  165. return Visibility.Hidden;
  166. }
  167. else
  168. {
  169. return Visibility.Hidden;
  170. }
  171. }
  172. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  173. {
  174. throw new NotImplementedException();
  175. }
  176. }
  177. public class IntToBoolConvert : IValueConverter
  178. {
  179. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  180. {
  181. if (value != null && value.ToString() == "1")
  182. {
  183. return true;
  184. }
  185. else
  186. {
  187. return false;
  188. }
  189. }
  190. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  191. {
  192. if (value is bool b)
  193. {
  194. if (b) return 1;
  195. return 0;
  196. }
  197. return 0;
  198. }
  199. }
  200. public class Int0ToBoolConvert : IValueConverter
  201. {
  202. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  203. {
  204. if (value != null && value.ToString() == "0")
  205. {
  206. return true;
  207. }
  208. else
  209. {
  210. return false;
  211. }
  212. }
  213. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  214. {
  215. if (value is bool b)
  216. {
  217. if (b) return 0;
  218. return 1;
  219. }
  220. return 1;
  221. }
  222. }
  223. public class BoolToVisibilityConvert : IValueConverter
  224. {
  225. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  226. {
  227. if (value is bool b && b)
  228. {
  229. return Visibility.Hidden;
  230. }
  231. return Visibility.Visible;
  232. }
  233. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  234. {
  235. throw new NotImplementedException();
  236. }
  237. }
  238. public class IsNullToVisibilityConvert : IValueConverter
  239. {
  240. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  241. {
  242. if (value == null)
  243. {
  244. return Visibility.Collapsed;
  245. }
  246. return Visibility.Visible;
  247. }
  248. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  249. {
  250. throw new NotImplementedException();
  251. }
  252. }
  253. public class StringToVisibilityConvert : IValueConverter
  254. {
  255. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  256. {
  257. if (value == null || string.IsNullOrEmpty(value.ToString())) return Visibility.Collapsed;
  258. return Visibility.Visible;
  259. }
  260. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  261. {
  262. throw new NotImplementedException();
  263. }
  264. }
  265. public class IntToDownStringConvert : IValueConverter
  266. {
  267. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  268. {
  269. try
  270. {
  271. if (value == null) return "";
  272. string string1 = "";
  273. switch (value.ToString())
  274. {
  275. case "0":
  276. //string1 = "排队中";
  277. string1 = KeyToStringConvert.GetLanguageStringByKey("0627");
  278. break;
  279. case "1":
  280. //string1 = "下载中";
  281. string1 = KeyToStringConvert.GetLanguageStringByKey("0626");
  282. break;
  283. case "2":
  284. //string1 = "失败";
  285. string1 = KeyToStringConvert.GetLanguageStringByKey("0625");
  286. break;
  287. case "3":
  288. //string1 = "已完成";
  289. string1 = KeyToStringConvert.GetLanguageStringByKey("0624");
  290. break;
  291. }
  292. return string1;
  293. }
  294. catch
  295. {
  296. return "";
  297. }
  298. }
  299. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  300. {
  301. throw new NotImplementedException();
  302. }
  303. }
  304. public class IntToDownColorConvert : IValueConverter
  305. {
  306. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  307. {
  308. try
  309. {
  310. if (value == null) return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  311. switch (value.ToString())
  312. {
  313. case "0":
  314. return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  315. case "1":
  316. return new SolidColorBrush(Colors.Blue);
  317. case "2":
  318. return new SolidColorBrush(Colors.Red);
  319. case "3":
  320. return new SolidColorBrush(Colors.Green);
  321. }
  322. return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  323. }
  324. catch
  325. {
  326. return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  327. }
  328. }
  329. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  330. {
  331. throw new NotImplementedException();
  332. }
  333. }
  334. }