PercentConverter.cs 891 Bytes
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace FLY.ControlLibrary.Converter
{
    class PercentConverter:IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double percent = (double)value;
            return (percent * 100).ToString("F1");
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double percent = 0;
            if (double.TryParse(value as string, out percent))
            {
                return percent / 100.0;
            }
            else
            {
                return 0;
            }
        }

        #endregion
    }
}