DataConverter.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Windows.Data;
  3. namespace VirgoUI.Client.Models.Converter
  4. {
  5. public class Bit2Bool : IValueConverter
  6. {
  7. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  8. {
  9. if (!(value is int))
  10. {
  11. return false;
  12. }
  13. int tempValue = (int)value;
  14. return tempValue == 1;
  15. }
  16. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  17. {
  18. if (!(value is bool))
  19. {
  20. return 0;
  21. }
  22. bool tempValue = (bool)value;
  23. return tempValue == true ? 1 : 0;
  24. }
  25. }
  26. public class Null2Bool : IValueConverter
  27. {
  28. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  29. {
  30. return value == null;
  31. }
  32. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  33. {
  34. throw new NotImplementedException();
  35. }
  36. }
  37. public class String2Double : IValueConverter
  38. {
  39. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  40. {
  41. if (value == null)
  42. return 0.0;
  43. double tempValue = 0.0;
  44. double.TryParse(value.ToString(), out tempValue);
  45. return tempValue;
  46. }
  47. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  48. {
  49. throw new NotImplementedException();
  50. }
  51. }
  52. public class Bool2Not : IValueConverter
  53. {
  54. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  55. {
  56. if (!(value is bool))
  57. return false;
  58. return !(bool)value;
  59. }
  60. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  61. {
  62. if (!(value is bool))
  63. return false;
  64. return !(bool)value;
  65. }
  66. }
  67. public class Float2String : IValueConverter
  68. {
  69. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  70. {
  71. if (value == null)
  72. return string.Empty;
  73. if (double.IsNaN((double)value))
  74. return string.Empty;
  75. else
  76. return value;
  77. }
  78. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  79. {
  80. throw new NotImplementedException();
  81. }
  82. }
  83. }