BooleanArr2BooleanConverter.cs 969 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Windows.Data;
  6. using HandyControl.Data;
  7. namespace HandyControl.Tools.Converter;
  8. public class BooleanArr2BooleanConverter : IMultiValueConverter
  9. {
  10. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  11. {
  12. if (values == null)
  13. {
  14. return ValueBoxes.FalseBox;
  15. }
  16. var arr = new List<bool>();
  17. foreach (var item in values)
  18. {
  19. if (item is bool boolValue)
  20. {
  21. arr.Add(boolValue);
  22. }
  23. else
  24. {
  25. return ValueBoxes.FalseBox;
  26. }
  27. }
  28. return ValueBoxes.BooleanBox(arr.All(item => item));
  29. }
  30. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  31. {
  32. throw new NotSupportedException();
  33. }
  34. }