注册 登录
编程论坛 WPF/Silverlight

WPF多路Binding遇到一点问题,求解?

tianqy 发布于 2013-01-24 11:49, 5835 次点击
//  接口+LognMultiBindingConverter类的定义:
namespace w8
{
    //IMultiValueConverter接口定义
    public interface IMultiValueConverter
    {
        object Convert(object[] values, Type targetType, object parameter, CultureInfo culture);
        object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture);
    }
    public class LognMultiBindingConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (!values.Cast<string>().Any(text => string.IsNullOrEmpty(text))
                && values[0].ToString() == values[1].ToString()
                && values[2].ToString() == values[3].ToString())
            {
                return true;
            }
            return false;
        }
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
//  “ mb.Converter = new LognMultiBindingConverter();”这里需要什么类型转换,怎么转换呢???
namespace w8
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private System.Windows.Data.IMultiValueConverter LognMultiBindingConverter;
        public MainWindow()
        {
            InitializeComponent();
            this.SetMultiBinding();
        }
        //设置MultiBinding的方法
        private void SetMultiBinding()
        {
            //准备基础Binding
            Binding b1 = new Binding("Text") { Source = this.textBox1 };
            Binding b2 = new Binding("Text") { Source = this.textBox2 };
            Binding b3 = new Binding("Text") { Source = this.textBox3 };
            Binding b4 = new Binding("Text") { Source = this.textBox4 };
            //准备MultiBinding
            MultiBinding mb = new MultiBinding() { Mode = BindingMode.OneWay };
            mb.Bindings.Add(b1);
            mb.Bindings.Add(b2);
            mb.Bindings.Add(b3);
            mb.Bindings.Add(b4);
            mb.Converter = new LognMultiBindingConverter();

            //将Button与MultiBinding对象关联
            this.button1.SetBinding(Button.IsEnabledProperty, mb);
        }
    }
}
错误如下:
错误    1    无法将类型“w8.LognMultiBindingConverter”隐式转换为“System.Windows.Data.IMultiValueConverter”。存在一个显式转换(是否缺少强制转换?)    F:\wpf\WPF1\w8\MainWindow.xaml.cs    43    28    w8
1 回复
#2
tianqy2013-01-24 13:07
问题解决了,自己粗心大意
1