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;
            if (strValue.IndexOf('.') == strValue.Length - 1 || !decimal.TryParse(strValue, out result))
                return DependencyProperty.UnsetValue;
            return result;
        }
    }
}