using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using System.Windows.Media; using Venus_Themes.CustomControls; namespace Venus_Themes.Converters { public class RingProgressArcConverter : IMultiValueConverter { // 注意,因为这里使用Path绘制圆环, 所以要把描边宽度大小考虑进去. 所有点的x、y偏移 半个描边宽度 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null) { return null; } double value; if (values[0] is double width && values[1] is double height && width > 0 && height > 0 && values[2] is double storkeWidth) { width -= storkeWidth; height -= storkeWidth; value = values.Length == 4 ? System.Convert.ToDouble(values[3]) : 1d; if (value == 0) return ""; var startAngle = -90d; var endAngle = Math.Min(value * 360 - 90, 269); var radius = Math.Min(width, height) * 0.5; var start = startAngle.AngleToPoint(radius, storkeWidth * 0.5); var end = endAngle.AngleToPoint(radius, storkeWidth * 0.5); var dataStr = $"M {start.X},{start.Y} A {radius},{radius} 0 {(endAngle - startAngle >= 180 ? 1 : 0)} 1 {end.X},{end.Y}"; var converter = TypeDescriptor.GetConverter(typeof(Geometry)); return (Geometry)converter.ConvertFrom(dataStr); } else { return ""; } } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }