AllNoneCheckboxConverter.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Data;
  7. using Venus_Core;
  8. namespace Venus_MainPages.Converters
  9. {
  10. public class AllNoneCheckboxConverter : IMultiValueConverter
  11. {
  12. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if (values == null) return false;
  15. bool result = (bool)values[0];
  16. for (int i = 0; i < values.Length; i++)
  17. if (result != (bool)values[i])
  18. return null;
  19. return result;
  20. }
  21. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  22. {
  23. object[] result = new object[targetTypes.Length];
  24. bool isChecked = (bool)value;
  25. for (int i = 0; i < result.Length; i++)
  26. if (isChecked)
  27. result[i] = true;
  28. else
  29. result[i] = false;
  30. return result;
  31. }
  32. }
  33. }