2012-01-27 73 views
0

对于C#,我正在通过Tutorial为MEF(Managed Extensibility Framework)工作,但由于这两个代码行无法获取实用程序工作,教程它们可以在界面的大局之下找到):在C#中设置组合框的ItemSource和DisplayMemberPath#

cbTransformationOptions.ItemsSource = _tranformationEngine.Transformers; 
cbTransformationOptions.DisplayMemberPath = "Name"; 

提到cbTransformationOptions是一个普通的组合框。该代码将无法编译,我发现了以下错误:

'System.Windows.Forms.ComboBox' does not contain a definition for 'ItemsSource' 
and no extension method 'ItemsSource' accepting a first argument of type 
'System.Windows.Forms.ComboBox' could be found (are you missing a using directive 
or an assembly reference?) 

'System.Windows.Forms.ComboBox' does not contain a definition for 'DisplayMemberPath' 
and no extension method 'DisplayMemberPath' accepting a first argument of type 
'System.Windows.Forms.ComboBox' could be found (are you missing a using directive 
or an assembly reference?) 

我想通了,直到如今,是,这两个声明都以某种方式连接到WPF/XAML(我发现在计算器上一些参考) - 但我对这个话题没有任何经验,所以这些答案根本没有帮助我。

如何让代码工作?

回答

1

System.Windows.Forms是创建wpf项目所需的错误名称空间。

+0

谢谢。我将代码复制到一个新的wpf项目中,并且它工作正常! – DIF 2012-01-27 09:46:37

1

本教程描述了一个WPF项目,而您似乎试图针对Windows Forms项目编译代码。

WPF是Windows Forms的替代演示技术,本身就是一个巨大的主题。如果您希望构建WPF项目,我建议您购买一本关于WPF的书。

我不知道你在.NET中的经验如何,但在C#2010中的临WPF提供了极好的覆盖率。

相关问题