MutliBoolConverter.cs 957 B

12345678910111213141516171819202122232425262728293031
  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. namespace ShakerApp.Convert
  8. {
  9. internal class MutliBoolConverter : Avalonia.Data.Converters.IMultiValueConverter
  10. {
  11. public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
  12. {
  13. if (values == null || values.Count == 0) return false;
  14. var bools = values.Select(x =>
  15. {
  16. if (x == null) return false;
  17. if (x is bool b) return b;
  18. else
  19. {
  20. if (bool.TryParse(x.ToString(), out b)) return b;
  21. return false;
  22. }
  23. }).ToList();
  24. bool v = true;
  25. bools.ForEach(x => v &= x);
  26. if (parameter == null) return v;
  27. else return !v;
  28. }
  29. }
  30. }