BoolToGridLengthConverter.cs 753 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Globalization;
  3. using Xamarin.Forms;
  4. namespace InABox.Mobile
  5. {
  6. public class BoolToGridLengthConverter : IValueConverter
  7. {
  8. public GridLength TrueValue { get; set; }
  9. public GridLength FalseValue { get; set; }
  10. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  11. {
  12. if ((value is bool bvalue) && bvalue)
  13. return TrueValue;
  14. return FalseValue;
  15. }
  16. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. if (value is GridLength length)
  19. return length.Equals(TrueValue);
  20. return false;
  21. }
  22. }
  23. }