You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AI.Converters
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 将 double? 转为 double,用于 NumericUpDown 的 Minimum/Maximum(null 时用默认边界)
|
|
|
|
|
|
/// ConverterParameter: "min" -> null 转为 double.MinValue, "max" -> null 转为 double.MaxValue
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FormNullableDoubleConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is double d)
|
|
|
|
|
|
{
|
|
|
|
|
|
return d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (value is decimal dec)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (double)dec;
|
|
|
|
|
|
}
|
|
|
|
|
|
var key = parameter?.ToString()?.ToLowerInvariant();
|
|
|
|
|
|
return key == "max" ? double.MaxValue
|
|
|
|
|
|
: key == "step" ? 1d
|
|
|
|
|
|
: double.MinValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
=> throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|