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; } } }