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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
namespace FLY.Winder.UI.Client.Converter
{
public class RatioConverter : IMultiValueConverter
{
#region IMultiValueConverter 成员
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values.Length == 3)//必须要检查,不然 界面生成器 会错误,提示转换异常
{
double ratio;
double value = System.Convert.ToDouble(values[0]);
double max = System.Convert.ToDouble(values[1]);
double ActualWidth = System.Convert.ToDouble(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;
}
else
{
return 100;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
#endregion
}
}