一、Xaml中绑定代码:
<TextBlock Grid.Row="5" Grid.Column="3">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource MultiStringStateConverter}" ConverterParameter="49.4-59.4">
<Binding Path="ZfMuscle"/>
<Binding Path="ZfResult"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
二、多值转换代码:
/// <summary> 根据参考值范围确定状态 </summary>
[ValueConversion(typeof(string), typeof(string))]
public class MultiStringStateConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null) return null;
if (values[0] == null) return null;
if (parameter == null) return string.Empty;
if (values.Length != 2) return null;
if (values[1] != null && values[1].ToString() == "###") return null;
var ps = parameter.ToString().Split(‘-‘);
if (ps.Length != 2) return null;
if (!ps[0].IsDouble() || !ps[1].IsDouble() || !values[0].ToString().IsDouble()) return string.Empty;
if (values[0].ToString().ToDouble() < ps[0].ToDouble()) return "↓";
if (values[0].ToString().ToDouble() > ps[1].ToDouble()) return "↑";
return string.Empty;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
三、作用:
根据绑定的两个值去做判断,用来显示结果