| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5816 人关注过本帖
标题:WPF多路Binding遇到一点问题,求解?
只看楼主 加入收藏
tianqy
Rank: 5Rank: 5
等 级:职业侠客
帖 子:260
专家分:332
注 册:2011-4-7
结帖率:91.43%
收藏
 问题点数:0 回复次数:1 
WPF多路Binding遇到一点问题,求解?
//  接口+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
搜索更多相关主题的帖子: namespace interface culture public 
2013-01-24 11:49
tianqy
Rank: 5Rank: 5
等 级:职业侠客
帖 子:260
专家分:332
注 册:2011-4-7
收藏
得分:0 
问题解决了,自己粗心大意

☞  软件驱动整个世界 ☜
2013-01-24 13:07
快速回复:WPF多路Binding遇到一点问题,求解?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010994 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved