40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
|
|||
|
|
namespace MembranePoreTester.Converters
|
|||
|
|
{
|
|||
|
|
// <20><> double <20><> string ֮<><D6AE><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>ȫת<C8AB><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ 0
|
|||
|
|
public class DoubleStringConverter : IValueConverter
|
|||
|
|
{
|
|||
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
if (value == null) return string.Empty;
|
|||
|
|
if (value is double d)
|
|||
|
|
{
|
|||
|
|
return d.ToString("G", culture);
|
|||
|
|
}
|
|||
|
|
return value.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
var s = (value as string) ?? string.Empty;
|
|||
|
|
s = s.Trim();
|
|||
|
|
if (string.IsNullOrEmpty(s))
|
|||
|
|
{
|
|||
|
|
// <20><>ǿ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>д<EFBFBD><D0B4>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
return Binding.DoNothing;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (double.TryParse(s, NumberStyles.Any, culture, out double result))
|
|||
|
|
{
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|||
|
|
return Binding.DoNothing;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|