Files
PropertyGrid/Avalonia.PropertyGrid/Converters/NumericFormatConverter.cs
T
2026-08-10 14:46:18 +02:00

34 lines
915 B
C#

using System;
using System.Globalization;
using Avalonia.Data.Converters;
namespace Avalonia.PropertyGrid.Controls;
/// <summary>
/// Converts PropertyType to appropriate numeric format string
/// </summary>
public class NumericFormatConverter : IValueConverter
{
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";
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}