wpf converter converterparameter 绑定多参数

1. converterparameter不是依赖属性,所以不能用binding。

2. 可以把converter 的接口 IValueConverter改为 IMultiValueConverter,实现多个  MultiBinding

3. IMultiValueConverter代码,例如:

    public class MultiBoolToColorConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var color = System.Windows.Media.Color.FromRgb(0x31, 0x89, 0xC6);// "#3189c6";


            if (values.All(v => (v is bool && (bool)v)) || values.All(v => (v is bool && (bool)v==false)))
            {
                color = System.Windows.Media.Color.FromRgb(0x89, 0xBB, 0xE0);//"#89BBE0";
            }

            return new System.Windows.Media.SolidColorBrush(color);
        }

        public object[] ConvertBack( object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

4.xmal文件写法,例如:

  
        "mutiBoolConverter"/>
    

 

OR

 

 

你可能感兴趣的:(wpf converter converterparameter 绑定多参数)