我的 WPF 应用程序找不到资源“Mainwindow.xaml”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15543570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
My WPF Application cannot locate resource 'Mainwindow.xaml'
提问by George
I have been working on a WPF application using vb.net and I've recently run into a problem.
我一直在使用 vb.net 开发 WPF 应用程序,但最近遇到了一个问题。
When I build my code, the build is successful but when it comes to running the code the System.IO.IOexception throws an exception "Cannot locate resource ViewModel/ViewModel/Mainwindow.xaml" The .Xaml windows are located in a folder called ViewModel hence I don't know where the other ViewModel/ViewModel... path is coming from, isn't it supposed to be viewModel/MainWindow.Xaml? I have tried all possible solutions including cleaning up the Project but it doesn't seem to work.
当我构建我的代码时,构建成功,但在运行代码时 System.IO.IOexception 抛出异常“无法找到资源 ViewModel/ViewModel/Mainwindow.xaml” .Xaml 窗口位于名为 ViewModel 的文件夹中因此我不知道其他 ViewModel/ViewModel... 路径来自哪里,难道它不应该是 viewModel/MainWindow.Xaml?我已经尝试了所有可能的解决方案,包括清理项目,但它似乎不起作用。
The only solution that seems to work is if I change the StartupUri from
StartupUri = "ViewModel\MainWindow.Xaml"
TO StartupUri = "...\MainWindow.xaml"
but I doubt if that is the right thing to do.
似乎唯一可行的解决方案是,如果我将 StartupUri 从StartupUri = "ViewModel\MainWindow.Xaml"
TO更改,
StartupUri = "...\MainWindow.xaml"
但我怀疑这是否正确。
回答by Arijit Mukherjee
Change the StartupUri="MainWindow.xaml"
to StartupUri="FolderName/MainWindow.xaml"
更改StartupUri="MainWindow.xaml"
为StartupUri="FolderName/MainWindow.xaml"
Solved my problem, when I moved my MainWindow to the View Folder
解决了我的问题,当我将 MainWindow 移动到 View Folder 时
回答by Alex Krotnyi
In my case I needed to use pack URI syntax to set SrartUpUri property of my App.xaml file to point to a new location of my MainWindow.xaml, as so:
就我而言,我需要使用 pack URI 语法来设置 App.xaml 文件的 SrartUpUri 属性以指向 MainWindow.xaml 的新位置,如下所示:
<Application x:Class="TrafficLights.Controller.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="pack://application:,,,/View/MainWindow.xaml">
More on pack URIs here:
更多关于包 URI 的信息:
http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx
Hope it helps. Good luck!
希望能帮助到你。祝你好运!
回答by Libor
This happened to me few times - always when I moved MainWindow.xaml
to different folder and forgot to update StartupUri
in App.xaml
.
这发生在我几次-总是当我移动MainWindow.xaml
到不同的文件夹,然后忘了更新StartupUri
在App.xaml
。
回答by jclstefan
Visual Studio has somehow renamed my MainWindow.xaml
to MainWindow(1).xaml
, so again I renamed it to MainWindow.xaml
Visual Studio 以某种方式将 my 重命名MainWindow.xaml
为MainWindow(1).xaml
,因此我再次将其重命名为MainWindow.xaml