步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
925 B

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace BBWY.Client.Converters
{
public class InputNumberConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string strValue = value as string;
if (string.IsNullOrEmpty(strValue))
return null;
decimal result;
var dotIndex = strValue.IndexOf('.');
if (dotIndex == strValue.Length - 1 ||
(dotIndex != -1 && strValue.EndsWith("0")) ||
!decimal.TryParse(strValue, out result))
return DependencyProperty.UnsetValue;
return result;
}
}
}