using System; using System.Globalization; using System.Windows.Data; namespace HC_APTBS.Converters { /// /// Maps a 0-100 percentage to a pixel value against a reference height supplied /// via 's parameter. Used by /// to project the /// tolerance band and target marker onto the fixed-height gauge track. /// public sealed class PercentToPixelsConverter : IValueConverter { /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double percent = value switch { double d => d, float f => f, int i => i, _ => 0.0 }; double height = parameter switch { double d => d, string s when double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var parsed) => parsed, _ => 0.0 }; if (double.IsNaN(percent) || double.IsNaN(height) || height <= 0) return 0.0; return Math.Clamp(percent, 0.0, 100.0) / 100.0 * height; } /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException(); } }