Commit a440b345 authored by 潘栩锋's avatar 潘栩锋 🚴

改进 RatioConverter 支持double输入

parent 01ee45d7
......@@ -9,35 +9,42 @@ namespace FLY.Thick.Base.UI.Converter
public class RatioConverter: IMultiValueConverter
{
#region IMultiValueConverter 成员
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
double getValue(object value)
{
if (values.Length == 3 && (values[0] is int) && (values[1] is int) && (values[2] is double))//必须要检查,不然 界面生成器 会错误,提示转换异常
if ((value is int) && (!Misc.MyBase.ISVALIDATA((int)value)))
return 0;
try
{
double ratio ;
int value = (int)values[0];
if (value == 99999998)
value = 0;
int max = (int)values[1];
double ActualWidth = (double)values[2];
if(max <=0)
ratio = 0;
else
ratio = (double)value / max;
if (ratio < 0)
ratio = 0;
else if (ratio > 1)
ratio = 1;
return ActualWidth * ratio;
return System.Convert.ToDouble(value);
}
else
catch
{
return 0;
}
}
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values.Length != 3) //必须要检查,不然 界面生成器 会错误,提示转换异常
{
return 100;
}
double ratio;
double value = getValue(values[0]);
double max = getValue(values[1]);
double ActualWidth = getValue(values[2]);
if (max <=0)
ratio = 0;
else
ratio = (double)value / max;
if (ratio < 0)
ratio = 0;
else if (ratio > 1)
ratio = 1;
return ActualWidth * ratio;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment