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>
|
|
|
|
|
|
/// 表单数字字段与字符串双向转换(NumericUpDown Value 与 CurrentValue 绑定)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FormNumberConverter : IValueConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is string s && double.TryParse(s?.Trim(), NumberStyles.Any, culture, out var n))
|
|
|
|
|
|
return n;
|
|
|
|
|
|
return 0d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is double d)
|
|
|
|
|
|
{
|
|
|
|
|
|
return d.ToString(culture);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (value is decimal dec)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dec.ToString(culture);
|
|
|
|
|
|
}
|
|
|
|
|
|
return "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|