IntToBoolConverter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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;
  8. using System.Windows.Data;
  9. namespace ivf_tl_Operate.Converts
  10. {
  11. public class IntToBoolConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (value == null)
  16. {
  17. return false;
  18. }
  19. else
  20. {
  21. if (value.ToString() == "0")
  22. return false;
  23. else
  24. return true;
  25. }
  26. }
  27. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  28. {
  29. if (value == null)
  30. {
  31. return 0;
  32. }
  33. else
  34. {
  35. if (bool.TryParse(value.ToString(), out bool result))
  36. {
  37. return result ? 1 : 0;
  38. }
  39. else
  40. {
  41. return 0;
  42. }
  43. }
  44. }
  45. }
  46. }