CornerRadiusSplitConverter.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. namespace HandyControl.Tools.Converter;
  6. public class CornerRadiusSplitConverter : IValueConverter
  7. {
  8. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  9. {
  10. if (value is CornerRadius cornerRadius)
  11. {
  12. if (parameter is string str)
  13. {
  14. var arr = str.Split(',');
  15. if (arr.Length != 4) return cornerRadius;
  16. return new CornerRadius(
  17. arr[0].Equals("1") ? cornerRadius.TopLeft : 0,
  18. arr[1].Equals("1") ? cornerRadius.TopRight : 0,
  19. arr[2].Equals("1") ? cornerRadius.BottomRight : 0,
  20. arr[3].Equals("1") ? cornerRadius.BottomLeft : 0);
  21. }
  22. }
  23. return value;
  24. }
  25. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  26. {
  27. throw new NotSupportedException();
  28. }
  29. }