SideMenuScrollerToVisibilityBool.cs 943 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Avalonia.Data.Converters;
  5. namespace SukiUI.Converters
  6. {
  7. public class SideMenuScrollerToVisibilityBool : IMultiValueConverter
  8. {
  9. public static SideMenuScrollerToVisibilityBool Up { get; } = new((x,y) => x > y);
  10. public static SideMenuScrollerToVisibilityBool Down { get; } = new((x, y) => x < y);
  11. private readonly Func<double, double, bool> _converter;
  12. public SideMenuScrollerToVisibilityBool(Func<double, double, bool> converter)
  13. {
  14. _converter = converter;
  15. }
  16. public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
  17. {
  18. if (values[0] is not double firstVal) return null;
  19. if (values[1] is not double secondVal) return null;
  20. return _converter(firstVal,secondVal);
  21. }
  22. }
  23. }