using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace MeterVision.Util
{
    public class SliderConvert : IValueConverter
    {
        //当值从绑定源传播给绑定目标时，调用方法Convert
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //if (value == null)
            //    return DependencyProperty.UnsetValue;
            //DateTime date = (DateTime)value;
            //return date.ToString("yyyy-MM-dd");
            try
            {
                return System.Convert.ToInt16(value);
            }
            catch
            {
                return 100;
            }
        }
        //当值从绑定目标传播给绑定源时，调用此方法ConvertBack
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //string str = value as string;
            //DateTime txtDate;
            //if (DateTime.TryParse(str, out txtDate))
            //{
            //    return txtDate;
            //}
            //return DependencyProperty.UnsetValue;
            return int.Parse(value.ToString());
        }
    }
}
