InfoBadgeOverflowConverter.cs 703 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Avalonia.Data.Converters;
  5. namespace SukiUI.Converters;
  6. public class InfoBadgeOverflowConverter: IMultiValueConverter
  7. {
  8. public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
  9. {
  10. var overflowSuffix = parameter as string ?? "+";
  11. if (!double.TryParse(values[0]?.ToString(), out var headerValue) || values[1] is not (int overflowValue and > 0))
  12. {
  13. return values[0];
  14. }
  15. if (headerValue > overflowValue)
  16. {
  17. return overflowValue + overflowSuffix;
  18. }
  19. return values[0];
  20. }
  21. }