WPF编程之找不到资源“window1.xaml”之谜

当你运行程序时提示:

找不到资源“window1.xaml”。

System.IO.IOException was unhandled
  Message="找不到资源“window1.xaml”。"
  Source="PresentationFramework"
  StackTrace:
       在 MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
       在 System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
       在 System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
       在 System.IO.Packaging.PackWebResponse.GetResponseStream()
       在 System.IO.Packaging.PackWebResponse.get_ContentType()
       在 MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
       在 MS.Internal.WpfWebRequestHelper.CreateRequestAndGetResponseStream(Uri uri, ContentType& contentType)
       在 System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       在 SDKSample.Window1.InitializeComponent()
       在 SDKSample.Window1..ctor()
       在 SDKSample.app.AppStartingUp(Object sender, StartupEventArgs e)
       在 System.Windows.Application.OnStartup(StartupEventArgs e)
       在 System.Windows.Application.<.ctor>b__0(Object unused)
       在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
       在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       在 System.Threading.ExecutionContext.runTryCode(Object userData)
       在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Windows.Threading.DispatcherOperation.Invoke()
       在 System.Windows.Threading.Dispatcher.ProcessQueue()
       在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       在 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       在 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       在 System.Windows.Threading.Dispatcher.Run()
       在 System.Windows.Application.RunInternal(Window window)
       在 System.Windows.Application.Run(Window window)
       在 System.Windows.Application.Run()
       在 SDKSample.app.Main()
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:


这个问题可以说是有点牛
为什么呢?
她在以前winform出现过,就是没有设定解决方案或是项目启动(窗体)
这个设定在VS中为解决方案或是项目属性中设置
但是你会问 我新建一个WpfApplication 时候 那里设定为空啊(Not Set)
呵呵 这个就不要问我 了,找不到资源“window1.xaml”解决方法就是设定解决方案启动为window1.xaml(启动窗体)
有时候VS很霸道,他就不给你设定window1.xaml为启动窗体,就是下拉列表就没有window1.xaml
怎么办?
直接用记事本打开项目文件比如Visual C# Project file
那个是个XML格式文件(不要问我什么是XML)
修改
  <StartupObject>Window1.xaml</StartupObject>
如果还是不行就新建一个工程,导入文件........

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值