BoolVisibilityConverter.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. namespace MECF.Framework.UI.Client.Ctrlib.Converter
  6. {
  7. public class BoolVisibilityConverter : IValueConverter
  8. {
  9. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. if (value == null)
  12. return Visibility.Visible;
  13. if (parameter != null)
  14. {
  15. return (bool)value == System.Convert.ToBoolean(parameter) ? Visibility.Visible : Visibility.Hidden;
  16. }
  17. var v = (bool)value;
  18. return v == true ? Visibility.Visible : Visibility.Hidden;
  19. }
  20. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  21. {
  22. throw new NotImplementedException();
  23. }
  24. }
  25. public class BoolCollapsedConverter : IValueConverter
  26. {
  27. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  28. {
  29. if (value == null)
  30. return Visibility.Visible;
  31. if (parameter != null)
  32. {
  33. return (bool)value == System.Convert.ToBoolean(parameter) ? Visibility.Visible : Visibility.Collapsed;
  34. }
  35. var v = (bool)value;
  36. return v == true ? Visibility.Visible : Visibility.Collapsed;
  37. }
  38. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  39. {
  40. throw new NotImplementedException();
  41. }
  42. }
  43. }