StringToBooleanConverter.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.ComponentModel;
  3. using System.Globalization;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public class StringToBooleanConverter : UtilityConverter<String,bool>
  8. {
  9. public bool HasValue { get; set; }
  10. protected override bool Convert(string value)
  11. {
  12. var empty = String.IsNullOrWhiteSpace(value);
  13. return HasValue
  14. ? !empty
  15. : empty;
  16. }
  17. public StringToBooleanConverter()
  18. {
  19. HasValue = true;
  20. }
  21. }
  22. public class StringWithDefaultValueConverter : IValueConverter
  23. {
  24. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. return String.IsNullOrWhiteSpace(value as String)
  27. ? parameter
  28. : value;
  29. }
  30. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  31. {
  32. throw new NotImplementedException();
  33. }
  34. }
  35. }