BorderCircularConverter.cs 862 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. namespace HandyControl.Tools.Converter;
  6. public class BorderCircularConverter : IMultiValueConverter
  7. {
  8. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  9. {
  10. if (values.Length == 2 && values[0] is double width && values[1] is double height)
  11. {
  12. if (width < double.Epsilon || height < double.Epsilon)
  13. {
  14. return new CornerRadius();
  15. }
  16. var min = Math.Min(width, height);
  17. return new CornerRadius(min / 2);
  18. }
  19. return DependencyProperty.UnsetValue;
  20. }
  21. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  22. {
  23. throw new NotSupportedException();
  24. }
  25. }