using System.Globalization; using Avalonia.Data; using Avalonia.Data.Converters; namespace ClaudeDo.Ui.Converters; /// /// For NumericUpDown.Value bound to a non-nullable numeric property. The control's Value is /// decimal? and goes null the moment the text box is empty — which is exactly what happens /// while the user clears a value to type a new one. Writing that null into an int/decimal /// target throws , so swallow it and leave the source untouched /// until a real number arrives. /// public class KeepLastNumberConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is null ? null : System.Convert.ToDecimal(value, culture); public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is null) return BindingOperations.DoNothing; return System.Convert.ChangeType(value, Nullable.GetUnderlyingType(targetType) ?? targetType, culture); } }