首页 新闻 会员 周边

WPF新建项目的问题

0
悬赏园豆:20 [已解决问题] 解决于 2012-08-17 09:44

昨天不知道怎么了,突然wpf新建项目后,报“当前上下文中不存在名称“InitializeComponent”” 首先,xaml和cs的命名空间和文件名都是一致的,但是就是找不到InitializeComponent()方法,比较奇怪,有谁遇到过此类问题吗?winform没有此类问题,声明一下,我是系统自动建立的项目,没有任何改动,直接编译,就报这个错误。怀疑是wpf那里设置的问题,但是对wpf还不太擅长,不知道是不是那里配置错误了,高手解答,给分

 

------ 已启动生成: 项目: WpfApplication3, 配置: Debug x86 ------ D:\CODE\WpfApplication3\WpfApplication3\MainWindow.xaml.cs(24,13): 错误 CS0103: 当前上下文中不存在名称“InitializeComponent”

编译完成 -- 1 个错误,0 个警告 生成启动时间为 2012/5/8 9:36:48。 ResolveAssemblyReferences:   将生成 TargetFramework 配置文件排除列表。 CoreResGen:   "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\resgen.exe" /useSourcePath /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationCore.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationFramework.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.DataSetExtensions.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xaml.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.Linq.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\WindowsBase.dll" /compile Properties\Resources.resx,obj\x86\Debug\WpfApplication3.Properties.Resources.resources   正在将资源文件“Properties\Resources.resx”处理到“obj\x86\Debug\WpfApplication3.Properties.Resources.resources”中。 GenerateTargetFrameworkMonikerAttribute: 正在跳过目标“GenerateTargetFrameworkMonikerAttribute”,因为所有输出文件相对于输入文件而言都是最新的。 CoreCompile:   C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationCore.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationFramework.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xaml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Xml.Linq.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\x86\Debug\WpfApplication3.exe /resource:obj\x86\Debug\WpfApplication3.Properties.Resources.resources /target:winexe App.xaml.cs MainWindow.xaml.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs "C:\Users\Administrator\AppData\Local\Temp\.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs"

生成失败。

已用时间 00:00:00.10 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

WPF
diorlv2010的主页 diorlv2010 | 初学一级 | 园豆:188
提问于:2012-05-08 09:56
< >
分享
最佳答案
0

WPF新建的每一个XAML对象,在其对应的模块的构造函数里,都会有调用InitializeComponent这个初始化方法,这个方法在我们的代码中是不存在的,因为这个函数会在系统编译的时候对XAML文档处理后自动生成,这个自动生成的文件可能是.g.cs之类的,在你的项目文件夹下的obj文件夹里(或其子文件夹中)能找到。

正常情况下,不应该有这个问题,你可以检查下你的XAML文档是否有效的UI(XML的根节点对象必须是一个UI对象),或者把OBJ文件夹删除后编译,或者使用REBUILD看。

收获园豆:20
无之无 | 大侠五级 |园豆:5095 | 2012-05-11 15:56

基本方法都用过,没用,奇怪,另一台机器没事

diorlv | 园豆:259 (菜鸟二级) | 2012-05-11 23:24

@diorlv: 你或者在这台计算机上再重新创建一个新项目看是否问题还是这样。

假如还是这样,那问题就很难界定了。我还没遇到过这样的情况。

无之无 | 园豆:5095 (大侠五级) | 2012-05-12 08:30

@笨笨蜗牛: 确实,创建了,还是此问题,我也无解,最后重新安装了VS解决

diorlv2010 | 园豆:188 (初学一级) | 2012-06-05 16:40

@diorlv2010: HOHO,这个是最郁闷的事情!

无之无 | 园豆:5095 (大侠五级) | 2012-06-05 16:41
其他回答(1)
0

重新安装了,是在没时间折腾这个问题

diorlv2010 | 园豆:188 (初学一级) | 2012-08-17 09:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册