StringToBoolConvert.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Data;
  8. namespace FurnaceUI.Converter
  9. {
  10. public class StringToBoolConvert : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if (value == null) return false;
  15. string s = value.ToString();
  16. bool.TryParse(s, out bool rtn);
  17. return rtn;
  18. }
  19. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  20. {
  21. throw new NotImplementedException();
  22. }
  23. }
  24. public class StringTVisibilityConvert : IValueConverter
  25. {
  26. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  27. {
  28. Visibility visibility = Visibility.Collapsed;
  29. if (value != null)
  30. {
  31. string s = value.ToString();
  32. if (bool.TryParse(s, out bool rtn))
  33. {
  34. visibility = rtn ? Visibility.Visible : Visibility.Collapsed;
  35. }
  36. }
  37. return visibility;
  38. }
  39. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  40. {
  41. return Binding.DoNothing;
  42. }
  43. }
  44. }