CountToColumnsConverter.cs 719 B

123456789101112131415161718192021
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. namespace TeamAAS_VP.ValueConverter
  5. {
  6. public class CountToColumnsConverter : IValueConverter
  7. {
  8. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  9. {
  10. if (value == null) return 1;
  11. if (!int.TryParse(value.ToString(), out int count)) return 1;
  12. if (count <= 1) return 1;
  13. if (count == 2) return 2;
  14. return 3; // 3 或更多时按 3 列分布(UniformGrid 会自动换行)
  15. }
  16. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  17. => throw new NotSupportedException();
  18. }
  19. }