BooleanToVisibilityConverter.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 TeamAAS_VP.ValueConverter
  10. {
  11. public class BooleanToVisibilityConverter : IValueConverter
  12. {
  13. public bool Invert { get; set; } = false;
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. if (value != null && value is bool b)
  17. {
  18. if (Invert)
  19. {
  20. return b ? Visibility.Collapsed : Visibility.Visible;
  21. }
  22. else
  23. {
  24. return b ? Visibility.Visible : Visibility.Collapsed;
  25. }
  26. }
  27. else
  28. {
  29. return Visibility.Collapsed;
  30. }
  31. }
  32. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  33. {
  34. return value is Visibility visibility && visibility == Visibility.Visible;
  35. }
  36. }
  37. }