CountToColumnsConverter.cs 840 B

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