AndMultiBoolValueConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Data;
  6. namespace Compdfkit_Tools.Common
  7. {
  8. public class AndMultiBoolValueConverter : IMultiValueConverter
  9. {
  10. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  11. {
  12. if (values != null && values.All(v => v is bool boolValue))
  13. {
  14. return values.Cast<bool>().All(v => v);
  15. }
  16. return DependencyProperty.UnsetValue;
  17. }
  18. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  19. {
  20. return Enumerable.Repeat(DependencyProperty.UnsetValue, targetTypes.Length).ToArray();
  21. }
  22. }
  23. public class OrMultiBoolValueConverter : IMultiValueConverter
  24. {
  25. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  26. {
  27. if (values != null && values.All(v => v is bool boolValue))
  28. {
  29. return values.Cast<bool>().Any(v => v);
  30. }
  31. return DependencyProperty.UnsetValue;
  32. }
  33. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  34. {
  35. return Enumerable.Repeat(DependencyProperty.UnsetValue, targetTypes.Length).ToArray();
  36. }
  37. }
  38. }