BoolVisibilityConverter.cs 661 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. namespace Bolt.Toolkit.Wpf.Converters
  6. {
  7. public class BoolVisibilityConverter : IValueConverter
  8. {
  9. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. var v = (bool)value;
  12. var hide = Visibility.Hidden;
  13. if (parameter != null)
  14. {
  15. if ((bool)parameter)
  16. {
  17. hide = Visibility.Collapsed;
  18. }
  19. }
  20. return v == true ? Visibility.Visible : hide;
  21. }
  22. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  23. {
  24. throw new NotImplementedException();
  25. }
  26. }
  27. }