using System.Globalization; using System.Windows.Data; namespace SharepointToolbox.Views.Converters; /// /// Converts a long byte value to a human-readable label for chart axes and tooltips. /// Similar to BytesConverter but implements IValueConverter for XAML binding. /// public class BytesLabelConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not long bytes) return value?.ToString() ?? ""; if (bytes < 1024) return $"{bytes} B"; if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB"; if (bytes < 1024 * 1024 * 1024) return $"{bytes / (1024.0 * 1024):F1} MB"; return $"{bytes / (1024.0 * 1024 * 1024):F2} GB"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException(); }