Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中设置ComboBox的ItemSource和DisplayMemberPath#_C#_Wpf_Combobox - Fatal编程技术网

C# 在C中设置ComboBox的ItemSource和DisplayMemberPath#

C# 在C中设置ComboBox的ItemSource和DisplayMemberPath#,c#,wpf,combobox,C#,Wpf,Combobox,我正在通过for MEF()for C#工作,但无法让示例项目wo工作,因为这两行代码(在链接教程中,它们可以在界面的大图下找到): 提到的cbTransformationOptions是一个普通的组合框。代码无法编译,我遇到以下错误: 'System.Windows.Forms.ComboBox' does not contain a definition for 'ItemsSource' and no extension method 'ItemsSource' accepting a

我正在通过for MEF()for C#工作,但无法让示例项目wo工作,因为这两行代码(在链接教程中,它们可以在界面的大图下找到):

提到的
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有某种联系(我在StackOverflow上找到了一些参考资料)——但我在这方面没有任何经验,所以这些答案对我毫无帮助


如何使代码正常工作?

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

本教程描述的是wpf项目,而您似乎正在尝试针对Windows Forms项目编译代码

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


我不知道您在.NET方面的经验有多丰富,但C#2010中的专业WPF提供了极好的覆盖范围。

谢谢。我将代码复制到一个新的wpf项目中,它成功了!
'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?)