using System; using System.Globalization; using Avalonia.Data.Converters; namespace Avalonia.PropertyGrid.Controls; /// /// Converts PropertyType to appropriate numeric format string /// public sealed class NumericFormatConverter : IValueConverter { /// /// Converts a Type to an appropriate numeric format string. /// /// The Type to convert. /// The target type. /// Optional parameter. /// Culture information. /// A format string like "N2" for floating point or "N0" for integers. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is Type type) { // Floating point types use decimal places if (type == typeof(float) || type == typeof(double) || type == typeof(decimal)) { return "N2"; // 2 decimal places } // Integer types use no decimal places return "N0"; } return "N0"; } /// /// Not supported for this converter. /// /// The value to convert back. /// The target type. /// Optional parameter. /// Culture information. /// Throws NotImplementedException. /// This converter does not support ConvertBack. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } }